Problem B

Cubes

 

You are given 12 rods of equal length. Each of them is colored in certain color. Your task is to determine in how many different ways one can construct a cube using these rods as edges. Two cubes are considered equal if one of them could be rotated and put next to the other, so that the corresponding edges of the two cubes are equally colored.

 

Input

The first line of input contains T (1≤T≤60), the number of test cases. Then T test cases follow. Each test case consists of one line containing 12 integers. Each of them denotes the color of the corresponding rod. The colors are numbers between 1 and 6.

 

Output

The output for one test consists of one integer on a line - the number of ways one can construct a cube with the described properties.

 

Sample Input

Sample Output

3

1 2 2 2 2 2 2 2 2 2 2 2

1 1 2 2 2 2 2 2 2 2 2 2

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

1

5

312120

 

Problem source: Bulgarian National Olympiad in Informatics 2003

Problem submitter: Ivaylo Riskov

Problem solution: Ivaylo Riskov, K M Hasan