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).

<image>| <image>
---|---
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.

<image>
---
Figure 3: examples of nets of a cube

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

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


Usually, a die is used in pair with another die. The plural form of the word "die" is "dice".

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

<image>
---
Figure 4: examples of proper nets of dice
<image>
---
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.

<image>| <image>
---|---
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.



Input

The input consists of multiple sheets of 5x5 mesh.

N
---
Mesh0
Mesh1
...
MeshN-1

N is the number of sheets of mesh. Each Meshi gives a sheet of mesh on which a net of a die is expressed. Meshi is in the following format.

F00 | F01 | F02 | F03 | F04
---|---|---|---|---
F10 | F11 | F12 | F13 | F14
F20 | F21 | F22 | F23 | F24
F30 | F31 | F32 | F33 | F34
F40 | F41 | F42 | F43 | F44

Each Fij is an integer between 0 and 6. They are separated by a space character.

Output

For each Meshi, the truth value, true or false, should be output, each in a separate line. When the net of a die expressed on the Meshi is proper, output "true". Otherwise, output "false".

Example

Input

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


Output

true
true
false
false
false
false
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

struct Dice {
   int b,f,l,r,u,d;

   void RollN()
  {
    //  --y;
    int buff = d;
    d = f;
    f = u;
    u = b;
    b = buff;
  }

  void RollS()
  {
    // ++y;
    int buff = d;
    d = b;
    b = u;
    u = f;
    f = buff;
  }

  void RollL() // ----->
  {
    int buff = f;
    f = l;
    l = b;
    b = r;
    r = buff;
  }

  void RollR() // <------
  {
    int buff = f;
    f = r;
    r = b;
    b = l;
    l = buff;
  }

  void RollE() // .o -> o.
  {
    // --x;
    int buff = d;
    d = l;
    l = u;
    u = r;
    r = buff;
  }


  void RollW() // o. -> .o
  {
    //  ++x;
    int buff = d;
    d = r;
    r = u;
    u = l;
    l = buff;
  }

};

//頑張った
void dfs(int x, int y, int f[5][5], Dice &dice, char c, vector<vector<bool>> visited){
   if(x >= 5 || x < 0 || y >= 5 || y < 0 || visited[y][x]){
      return;
   }

   visited[y][x] = true;
   if(f[y][x] == 0){
      return;
   }

   if(c == 'r') dice.RollL();
   if(c == 'l') dice.RollR();
   if(c == 'u') dice.RollS();
   if(c == 'd') dice.RollN();

   dice.b = f[y][x];


   dfs(x+1, y, f, dice, 'r', visited);
   dfs(x-1, y, f, dice, 'l', visited);
   dfs(x, y+1, f, dice, 'd', visited);
   dfs(x, y-1, f, dice, 'u', visited);

   if(c == 'r') dice.RollR();
   if(c == 'l') dice.RollL();
   if(c == 'u') dice.RollN();
   if(c == 'd') dice.RollS();
}

int main(){
   int n; cin>>n;
   while(n--){
      int f[5][5];
      vector<int> nums(7, 0);
      int x, y;
      for(int i=0; i<5; i++){
         for(int j=0; j<5; j++){
            cin>>f[i][j];
            nums[f[i][j]]++;
            if(f[i][j] != 0) x=j,y=i;
         }
      }

      //1-6の出現回数が1ならok
      bool flag = false;
      for(int i=1; i<7; i++){
         if(nums[i] != 1) flag = true;
      }
      if(flag){
         cout << "false" << endl;
         continue;
      }

      Dice dice = {0, 0, 0, 0, 0, 0};
      vector<vector<bool>> visited(5, vector<bool>(5, false));
      dfs(x, y, f, dice, 'b', visited);

      cout << ((dice.b + dice.f == 7 && dice.l+dice.r == 7 && dice.u+dice.d == 7) ? "true" : "false") << endl;
   }
}
