Self-organization of plasticity and specialization in a primitively social insect