11234 - Magic Square   

Description

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.

Input

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, yvalue:

  1. x is the specified x coordinate, which should be 0, 1, or 2
  2. y is the specified y coordinate, which should be 0, 1, or 2
  3. value is some number in the given set(in the second line), and its position is at (x,y).
    Notice that (0,0) is at the left-top position.

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.

Output

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.

Sample Input  Download

Sample Output  Download

Tags

2016F_Lee_Lab5



Discuss