{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eThis is a very popular game for children. In this game, there\u0027s a cube, which \n consists of 3 * 3 * 3 small cubes. We can unwrap the cube, it will become like \n this:\u003c/p\u003e\n\u003cp\u003e \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n r r r g g g b b b o o o\u003cbr\u003e\n r r r g g g b b b o o o\u003cbr\u003e\n r r r g g g b b b o o o\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003c/p\u003e\n\u003cp\u003e The letters means the color on the small cubes. For example, \u0027r\u0027 means red, \n \u0027g\u0027 means green, \u0027y\u0027 means yellow....The goal for this game is to rotate the \n faces of the cube to make each of the faces contains only one color. Note there\u0027re \n exact 6 kind of colors on the cube and there\u0027re exact 9 small rectangles totally \n in any time in the game.\u003c/p\u003e\n\u003cp\u003e Do you know how to rotate the faces? I think most of you have known it. But \n I would like to show it again. When a face is rotated, the configuration of \n colors in all the adjacent faces changes. For the cube above, after we rotate \n the green face clock-wise, the last line of \u0027w\u0027 face will become the left column \n of \u0027b\u0027 face, the left column of \u0027b\u0027 face will become the top line of \u0027y\u0027 face, \n etc. As you may know, reaching the final position from a scrambled configuration \n can be quite challenging.\u003c/p\u003e\n\u003cp\u003e In this problem, you are given a configuration of the cube, and asked to give \n a way to reach the final position. To reduce the difficulty, the steps required \n will never be greater than 5.\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eInput\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e The input contains an integer in the first line, which indicates the number \n of the test cases. In each test case, there\u0027re exact 10 lines. The first line \n is an empty line. The next 9 lines contain a configuration. The format can be \n seen in the sample input. For simplicity, we give an index to each face as follows: \n\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;/---\\\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;| \u0026nbsp;\u0026nbsp;|\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;| 4 |\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;| \u0026nbsp;\u0026nbsp;|\u003cbr\u003e\n /---+---+---+---\\\u003cbr\u003e\n | \u0026nbsp;\u0026nbsp;|\u0026nbsp;\u0026nbsp; |\u0026nbsp;\u0026nbsp; |\u0026nbsp;\u0026nbsp; |\u003cbr\u003e\n | 0 | 1 | 2 | 3 |\u003cbr\u003e\n | \u0026nbsp;\u0026nbsp;|\u0026nbsp;\u0026nbsp; |\u0026nbsp;\u0026nbsp; |\u0026nbsp;\u0026nbsp; |\u003cbr\u003e\n \\---+---+---+---/\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;| \u0026nbsp;\u0026nbsp;|\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;| 5 |\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;| \u0026nbsp;\u0026nbsp;|\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\\---/\u003c/p\u003e\n\u003cp\u003e Note that there\u0027s a space between two adjacent letters.\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eOutput\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e For each test case, the first line of the output is the smallest count N of \n the steps to reach the winning position. If the winning position can\u0027t be reached \n in 5 steps, print -1 in this line. Otherwise print each step in one line in \n the following N lines. A step contains two integers, the first one means the \n face index, and the second one means the direction. 1 means clock-wise and -1 \n means counter clock-wise. If the given position is the winning position, print \n 0 for such test case simply. If there\u0027re multiple solutions, any one is acceptable.\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eSample Input\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e 2\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n r r r g g g b b b o o o\u003cbr\u003e\n r r r g g g b b b o o o\u003cbr\u003e\n r r r g g g b b b o o o\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003c/p\u003e\n\u003cp\u003e \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;w w w\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;b b b\u003cbr\u003e\n r r w g g g y b b o o o\u003cbr\u003e\n r r w g g g y b b o o o\u003cbr\u003e\n r r w g g g y b b o o o\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;r r r\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003cbr\u003e\n \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;y y y\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eSample Output\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e 0\u003cbr\u003e\n 1\u003cbr\u003e\n 1 1\u003cbr\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\u003cbr\u003e\n\u003c/p\u003e\n"}}]}