Two grams of NaOH is equal to 2/40 mole = 1/20 mole.
Each molecule of NaOH gives one ion of OH-. When two grams of NaOH is dissolved in 500 mL of water we get a OH- molar concentration of (1/20)/(1/2) = 1/10 mol/L.
100 mL of this solution is mixed with 900 mL of distilled water, the molar concentration of OH- is 100*(1/10)/1000
=> 100/10000
pH = 14 - pOH
pOH = -log([OH-])
=-log(1/100)
=> 2
pH = 14 - 2 = 12
The pH of the solution formed when 2 grams of NaOH are dissolved in 500ml of water and then 100 ml of this solution is mixed with 900 ml of distilled water is 12.