eolymp
bolt
Try our new interface for solving problems
Problems

Rubiks Cube

Rubiks Cube

\includegraphics{https://static.e-olymp.com/content/03/033ca4bc5305c9b111a2d5f9b68abe8383fe2221.jpg} Following the hype generated by Rubiks Cube Norwegian Open Championship arranged at NTNU this year, each and every student at NTNU has bought such a cube. The professors, however, are dismayed, because the students rather play with their cube instead of listening to the professors lectures. One professor suddenly gets the idea that if he gives the students a program to solve their cubes they may lose interest in it, so that it will be possible to start teaching again. Of course, the professor don't want to do the grunt work of programming, and you are the lucky assignee of this task. The professor takes away your cube, locks you in a faraway laboratory and says that you won't get out until you have written a program to solve Rubiks cube. Luckily, the professor did not specify the size of the cube, so you decide to make the work slightly easier by solving the Rubiks \textbf{2}×\textbf{2}×\textbf{2} cube. \InputFile The first line of the input consists of a single number \textbf{T} (\textbf{0 < T ≤ 100}), the number of test cases. Each test case consists of six lines describing the initial con guration of a cube, formatted exactly as in the example input. The characters used for colors are \textbf{G}, \textbf{R}, \textbf{O}, \textbf{B}, \textbf{Y} and \textbf{W}. Each test case is followed by an empty line. You may assume that all input cubes are scrambled versions of originally solved cubes with six dierent colors. (Which means there are exactly four occurrences of each color and that it is possible to get the cube to a solved state using moves as described above.) \OutputFile For each scenario, output a line with the minimum number of moves that is necessecary to solve the cube. A move is turning one face of the cube \textbf{90} degrees clockwise or counter-clock wise. A turn of \textbf{180} degrees is considered to be two moves.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
OO
OO
RRGGBBWW
RRGGBBWW
YY
YY

RR
RR
YYOOGGBB
OOGGBBYY
WW
WW
Output example #1
0
1