Write the configuration of a magnesium atom? Will the atom lose or gain electrons? Explain using the idea of stability and energy.