The atomic number of magnesium is 12. The arrangement of electrons in a magnesium atom is 2, 8, 2.
Hence, the number of valence electrons in magnesium is 2.
Moving to sulphur. The atomic number of sulphur is 16. The arrangement of electrons in the sulphur atom is 2, 8, 6.
Hence, the number of valence electrons in the sulphur atom is 6.
The next element is argon. The atomic number of argon is 18. Therefore, the arrangement of electrons in argon atom is 2, 8, 8.
Hence , the number of valence electrons in argon atom is 8.