Nets of Dice

In mathematics, some plain words have special meanings.
The word "*net*" is one of such technical terms.
In mathematics, the word "*net*" is sometimes used to
mean a plane shape
which can be folded into some solid shape.

The following are a solid shape (Figure 1) and one of its *net* (Figure 2).

Figure 1: a prism | Figure 2: a net of a prism |

Nets corresponding to a solid shape are not unique. For example, Figure 3 shows three of the nets of a cube.

Figure 3: examples of nets of a cube |

In this problem, we consider nets of dice. The definition of a die is as follows.

- A die is a cube, each face marked with a number between one and six.
- Numbers on faces of a die are different from each other.
- The sum of two numbers on the opposite faces is always 7.

Some examples of proper nets of dice are shown in Figure 4, and those of improper ones are shown in Figure 5.

Figure 4: examples of proper nets of dice |

Figure 5: examples of improper nets |

The reasons why each example in Figure 5 is improper are as follows.

- (a) The sum of two numbers on the opposite faces is not always 7.
- (b) Some faces are marked with the same number.
- (c) This is not a net of a cube. Some faces overlap each other.
- (d) This is not a net of a cube. Some faces overlap each other and one face of a cube is not covered.
- (e) This is not a net of a cube. The plane shape is cut off into two parts. The face marked with '2' is isolated.
- (f) This is not a net of a cube. The plane shape is cut off into two parts.
- (g) There is an extra face marked with '5'.

Notice that there are two kinds of dice. For example, the solid shapes formed from the first two examples in Figure 4 are mirror images of each other.

Any net of a die can be expressed on a sheet of 5x5 mesh like the one in Figure 6. In the figure, gray squares are the parts to be cut off. When we represent the sheet of mesh by numbers as in Figure 7, squares cut off are marked with zeros.

Figure 6: 5x5 mesh | Figure 7: representation by numbers |

Your job is to write a program which tells the proper nets of a die from the improper ones automatically.

The input consists of multiple sheets of 5x5 mesh.

N |

Mesh_{0} |

Mesh_{1} |

... |

Mesh_{N-1} |

*N* is the number of sheets of mesh.
Each *Mesh _{i}* gives a sheet of mesh
on which a net of a die is expressed.

F_{00} |
F_{01} |
F_{02} |
F_{03} |
F_{04} |

F_{10} |
F_{11} |
F_{12} |
F_{13} |
F_{14} |

F_{20} |
F_{21} |
F_{22} |
F_{23} |
F_{24} |

F_{30} |
F_{31} |
F_{32} |
F_{33} |
F_{34} |

F_{40} |
F_{41} |
F_{42} |
F_{43} |
F_{44} |

Each *F _{ij}* is an integer between 0 and 6.
They are separated by a space character.

6 0 0 0 0 0 0 0 0 0 6 0 2 4 5 3 0 0 1 0 0 0 0 0 0 0 0 0 3 0 0 0 0 2 0 0 0 0 4 1 0 0 0 0 5 0 0 0 0 6 0 0 0 0 3 0 0 0 2 5 0 0 4 1 0 0 0 0 6 0 0 0 0 0 0 0 0 6 2 0 0 0 0 4 0 0 0 1 5 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 6 0 2 4 5 3 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 6 0 2 4 5 3 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

true true false false false false