YS begins to precipitate when its ionic product first reaches Ksp: [Y2+][S2−] = 4 × 10−16. Before precipitation of YS, [Y2+]≈ 0.01 M, so the required [S2−] is (10−2)(4 × 10−16) = 4 × 10−14 M.
Multiplying the two acid-dissociation equilibria of H2S gives Ka1Ka2=[H+]2[S2−]/[H2S]. Hence [H+]2=(4 × 10−14)(10−21 × 0.1) = 2.5 × 10−9.
Using the supplied logarithms, log(2.5) = log(25) = 0.70 − 0.30 = 0.40. Therefore 2 log[H+] = 0.40 − 9 = −8.60, giving pH = −log[H+] = 4.30.
At this sulfide concentration, the remaining free X2+ in equilibrium with XS would be Ksp(XS)/[S2−]=(4 × 10−14)10−22 = 2.5 × 10−9 M. Thus XS precipitates well before YS, consistent with its much smaller solubility product.
The onset pH is approximately 4.30, which rounds to the requested nearest integer 4.