Set each trolley's mass and signed velocity. Choose a collision type, then predict their motion after impact. Momentum p = mv has direction: a trolley moving left has negative velocity in this model. For an isolated pair of trolleys, total momentum before collision equals total momentum after collision, even when kinetic energy is not conserved.
In a perfectly elastic collision, both momentum and kinetic energy are conserved. In a perfectly inelastic collision the trolleys move together, while some kinetic energy transfers to deformation, sound or heating. The track here is one-dimensional and frictionless. Real impacts usually lie between these ideal cases, and an external force can change the momentum of the chosen system.
Check your understanding: Can momentum be conserved when the trolleys lose kinetic energy? Explain where that energy goes.