UVa 10067 - Playing with Wheels

Explanaion
Considering the machine's states as graph vertices, do a BFS and find the shortest path. Exclude restricted states from search.