Ask: Does the demonstrative point to the mudaf or the mudaf ilayh?
Mudaf target: بَيْتُ الْمُعَلِّمِ هَذَا. Mudaf-ilayh target: بَيْتُ هَذَا الْمُعَلِّمِ.
Important contrast: مَسَاجِدُ الْمَدِينَةِ هَذِهِ uses feminine-singular هَذِهِ because a non-human broken plural is treated as feminine singular for agreement here.