#P9529. Uva10601 Cubes

Uva10601 Cubes

Description

You are given 12 rods of equal length. Each of them is colored in certain color. Your task is to det ermine 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 correspondin g edges of the two cubes are equally colored.

要求把正方体的12条棱染色,并且每种颜色的个数给定,求总方案数(旋转后相同的方案算一种)

Format

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.

Samples

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