Railway Line

This is a single railway line with a loop. 
There is only room for eight wagons, or seven wagons and an engine, between B and C on either the left line or the right line of the loop. 
It happened that two goods trains (each consisting of an engine and sixteen wagons) got into the position shown in the illustration. 
It looked like a hopeless deadlock, and each engine-driver wanted the other to go back to the next station and take off nine wagons. 
But an ingenious stoker undertook to pass the trains and send them on their respective journeys with their engines properly in front. He also contrived to reverse the engines the fewest times possible. 
Could you have performed the feat? 
And how many times would you require to reverse the engines? 
A "reversal" means a change of direction, backward or forward. 
No rope-shunting, fly-shunting, or other trick is allowed. 
All the work must be done legitimately by the two engines. 

See answer

Math Genius