I spent about 6 hours solving this one. It took me a while to realize that every movement had to be saved on a stack. Then I developed diagrams, models, and a logical structure around it. And eventually stumbled my way to the solution logically. But it all seems so intuitively obvious now.