# 描述

This is a very popular game for children. In this game, there’s a cube, which consists of 3 3 3 small cubes. We can unwrap the cube, it will become like this:

The letters means the color on the small cubes. For example, ‘r’ means red, ‘g’ means green, ‘y’ means yellow….The goal for this game is to rotate the faces of the cube to make each of the faces contains only one color. Note there’re exact 6 kind of colors on the cube and there’re exact 9 small rectangles totally in any time in the game.
Do you know how to rotate the faces? I think most of you have known it. But I would like to show it again. When a face is rotated, the configuration of colors in all the adjacent faces changes. For the cube above, after we rotate the green face clock-wise, the last line of ‘w’ face will become the left column of ‘b’ face, the left column of ‘b’ face will become the top line of ‘y’ face, etc. As you may know, reaching the final position from a scrambled configuration can be quite challenging.
In this problem, you are given a configuration of the cube, and asked to give a way to reach the final position. To reduce the difficulty, the steps required will never be greater than 5.

# 输入

The input contains an integer in the first line, which indicates the number of the test cases. In each test case, there’re exact 10 lines. The first line is an empty line. The next 9 lines contain a configuration. The format can be seen in the sample input. For simplicity, we give an index to each face as follows:

Note that there’s a space between two adjacent letters.

# 输出

For each test case, the first line of the output is the smallest count N of the steps to reach the winning position. If the winning position can’t be reached in 5 steps, print -1 in this line. Otherwise print each step in one line in the following N lines. A step contains two integers, the first one means the face index, and the second one means the direction. 1 means clock-wise and -1 means counter clock-wise. If the given position is the winning position, print 0 for such test case simply. If there’re multiple solutions, any one is acceptable.

• Input

• Output
0
1
1 1

# 题解

• 题意：给出魔方六面，每一面标号如上，给出一种排列，你需要把它复原，求最少步数和步骤，不能超过5步。1表示顺时针，-1表示逆时针。
• 迭代深搜，deep从1到5。贼恶心一题，详细步骤看代码

# Code

Donate comment here