UVa 10067 - Playing with Wheels

Link
http://icpcres.ecs.baylor.edu/onlinejudge/external/100/10067.htm

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