Step 1 (general pattern): Ketones undergo condensation with nitrogen nucleophiles of the type \(H_2N-G\): an unstable carbinolamine forms first and then dehydrates to a \(C=N-G\) linkage. Which product forms depends on \(G\).
Step 2 (reaction i): With \(G = OH\) (hydroxylamine) the C=N-OH function is an oxime. From cyclopentanone, [A] is cyclopentanone oxime.
Step 3 (reaction ii): With \(G = NH-C_6H_3(NO_2)_2\) (2,4-dinitrophenylhydrazine) the product is a 2,4-dinitrophenylhydrazone. From cyclohexanone, [B] is cyclohexanone 2,4-dinitrophenylhydrazone, the coloured derivative used to confirm a carbonyl compound.
Step 4 (reaction iii): Phthalic acid has two neighbouring \(-COOH\) groups. Ammonia first neutralises them to the ammonium salt [A] (ammonium phthalate). Heating drives off water so the two acyl groups close a ring with one nitrogen, yielding the cyclic imide phthalimide [B].
\(\boxed{A = \text{ammonium phthalate},\; B = \text{phthalimide}}\)