(N/A) If the number of electrons in the outermost shell of an atom is less than or equal to $4$,the valency is equal to the number of valence electrons.
If the number of electrons in the outermost shell is greater than $4$,the valency is determined by subtracting the number of valence electrons from $8$.
The electronic configurations are:
Chlorine $(Z=17)$: $2, 8, 7$
Sulphur $(Z=16)$: $2, 8, 6$
Magnesium $(Z=12)$: $2, 8, 2$
For Chlorine: The outermost shell has $7$ electrons. Since $7 > 4$,valency $= 8 - 7 = 1$.
For Sulphur: The outermost shell has $6$ electrons. Since $6 > 4$,valency $= 8 - 6 = 2$.
For Magnesium: The outermost shell has $2$ electrons. Since $2 \leq 4$,valency $= 2$.