The input contains several test cases. The first line of each test case contains an integer N, the number of cubes in the set (1≤N≤1000). The next 3N lines describe the cubes of the set. Colors are identified by the integers 0 to 9.
Each cube is given in three lines that show the colors of the six faces of the "unfolded" cube, in the format below.
1
2 4 5 6
3
In this example the faces of the cube have colors 1 to 6. The face with color 1 is opposite the face with color 3. The face with color 2 is adjacent to the faces with colors 1, 3, 4, and 6, and it is opposite the face with color 5.
The end of input is marked by N=0.