39. Why do beryllium and magnesium not impart colour to the flame in the flame test?

All alkaline earth metals (except Be and Mg) impart a characteristic colour to the Bunsen flame. The different colours arise due to different energies required for electronic excitation and de-excitation.
Be and Mg atoms due to their small size, bind their electrons more strongly (because of higher effective nuclear charge). Hence, require high excitation energy and are not excited by the energy of the flame with the result that no flame colour is shown by them.