Systematic Generalization and Emergent Structures in Transformers Trained on Structured Tasks