시간 제한
메모리 제한

Kids love to challenge each other playing the Tobo. Starting with the arrangement shown in figure (a), (which we’ll call the standard arrangement,) one kid would randomly rotate the dials, X number of times, in order to ‘shuffle” the board. Another kid then tries to bring the board back to its standard arrangement, taking no more than X rotations to do so. The less rotations are needed to restore it, the better. This is where you see a business opportunity. You would like to sell these kids a program to advise them on the minimum number of steps needed to bring a Tobo back to its standard arrangement.
Your program will be tested on one or more test cases. Each test case is specified on a line by itself. Each line is made of 10 decimal digits. Let’s call the first digit Y. The remaining 9 digits are non-zeros and describe the current arrangement of the Tobo in a row-major top-down, left-to-right ordering. The first sample case corresponds to figure (c).
The last line of the input file is a sequence of 10 zeros.
For each test case, print the result using the following format:
k.␣R
where k is the test case number (starting at 1,) ␣ is a single space, and R is the minimum number of rotations needed to bring the Tobo back to its standard arrangement. If this can’t be done in Y dials or less, then R=-1.