Ok, this is not trial and error. So throw that out of the window. You need to assume that the cars can be left on the straight lines to the left of the circle.
Ok, label everything
T = locomotive
A = car A
B = car B
and then label the positions starting from the top left of the diagram. P1, P2, P3, P4, P5, P6
P1 = being where the locomotive (T) is now. (Upper left straightaway)
P2 = being where car A is
P3 = tunnel
P4 = where car B is
P5 = lower left straightaway
P6 = curve opposite the tunnel
Now you can describe everything.
T takes A goes to P4 and takes B. So ATB at P4
go straight to P5 and leave A, TB to P5
TB to P2, TB turns to BT, BT to P1, leave B at P1
Can you take it from here?