How and why men became eunuchs in imperial China