A magic squre is a matrix of numbers where every row, column and two diagonals sum to the same number. For example, integers from 1 to 9 can form a 3-by-3 magic square as follows:
6 1 8
7 5 3
2 9 4
In this problem, you have to calculate how many magic squares can be constructed given a set of integers with a restriction.
The first line of the input: the number of test cases in this input.
This number is less than 10.
Each test case has two lines;
The first line of a test case contains the restriction in three numbers, x, y, value:
and the second line has 9 distinct integers which are the set of numbers to be constructed as 3-by-3 magic squares. All of them are representable in the int type of C.
For each test case, you should calculate the number of magic squares that the 9 integers can construct, given the condition that the specified value is at the position (x, y).
For example, if a test case is like:
0 1 1
1 2 3 4 5 6 7 8 9
You are asked to calculate how many cases in the form
x x x
1 x x
x x x
is available, where x should be filled with remaining 8 numbers.
The answer of this part should be 2 becasue
6 7 2
1 5 9
8 3 4
and
8 3 4
1 5 9
6 7 2
are all the magic squares you can find.