Let v be the velocity of trolley B after collision. Then by conservation of momentum,
(3 kg) (8 m/s) + (4 kg) (9 m/s) = (3 kg) (9 m/s) + (4 kg) v
Solve for v :
24 kg•m/s + 36 kg•m/s = 27 kg•m/s + (4 kg) v
33 kg•m/s = (4 kg) v
v = (33 kg•m/s) / (4 kg) = 8.25 m/s