Although your question is a bit convoluted, I think I understand your problem. The problem you have is that you are relating master tables with detail tables. Let me explain, the students table is a detail table and the material table is a master table (like the race table). If you do the relationship directly you would have to repeat records in the tables of carrereas and matters. To make these relationships should be (I think I have not left any):
- MATERIA-> CARRERA
- MATTER-> TEACHING
- STUDENTS RELATIVE ALUMINUM < - & MATERIA (because a student can have more than one subject)
Students do not have to relate to teachers because they are related by subject, since a student will have more than one subject and, therefore, more than one teacher.
It's easier if you think about it naturally and then you move it to tables if you try to fight directly with tables.
It has been a bit long but I hope it will help you.