So first we have to solve for the total momentum of the entire system. We can do this by solving momentum for the first train. The equation for momentum is p=mv, where "p" is momentum.
Total momentum is

When the first train comes to a complete stop, it is an elastic collision. We can use conservation of momentum to solve for the velocity of the second train.

If they stick completely, then it is an inelastic collision. Here we have to combine the mass of the two trains and solve for the velocity.

Finally, if the train is 20m/s then what is the velocity of the first train. Just like before, we can solve using conservation of momentum.
