Solution:
Concept: The cation of a salt is found from its flame colour and from the colour of the hydroxide precipitate it gives with sodium hydroxide or ammonium hydroxide (and whether that precipitate dissolves in excess). The anion is found from the gas a dilute acid gives, or from the precipitate silver nitrate gives.
Step 1 — (i) Cation of P from the flame test.
A lilac flame is the flame colour of potassium, so salt P contains potassium ions, K+.
Step 2 — (i) Anion of P from silver nitrate.
A white precipitate with silver nitrate that dissolves in ammonium hydroxide is silver chloride, so the anion is chloride, Cl−. The silver chloride dissolves because it forms a soluble complex with ammonia.
KCl+AgNO3→AgCl↓+KNO3
AgCl+2NH4OH→[Ag(NH3)2]Cl+2H2O
Putting the two ions together, P is potassium chloride, KCl.
Step 3 — (ii) Anion of Q from dilute HCl.
Brisk effervescence of a gas that turns lime water milky shows carbon dioxide, so the anion is carbonate, CO32−.
ZnCO3+2HCl→ZnCl2+H2O+CO2↑
Ca(OH)2+CO2→CaCO3↓+H2O
Step 4 — (ii) Cation of Q from ammonium hydroxide.
The solution now holds the chloride of Q's metal. Ammonium hydroxide gives a white precipitate that dissolves in excess: that is zinc hydroxide, so the cation is zinc, Zn2+.
ZnCl2+2NH4OH→Zn(OH)2↓+2NH4Cl
Zn(OH)2+2NH4Cl+2NH4OH→[Zn(NH3)4]Cl2+4H2O
Lead hydroxide is also white but does not dissolve in excess ammonium hydroxide, and calcium gives no precipitate with it. So Q is zinc carbonate, ZnCO3.

Watch out: The precipitate that dissolves in excess AMMONIUM hydroxide is zinc hydroxide; lead hydroxide dissolves in excess SODIUM hydroxide but not in excess ammonium hydroxide.
Therefore, P is potassium chloride (KCl) and Q is zinc carbonate (ZnCO₃).