ZOJ month contest D.Determinant and Matrix

Time Limit: 2 Seconds Memory Limit: 65536 KB

Description

Recently, LBH is learning the curse linear algebra. Thus he is very interested in matrix and determinant now. In order to practice his ability of solving the problem of linear algebra, he just invent some problems by himself. Once the problems was create, he would solve it immediately. However, he meet a problem that was so hard that he couldn’t work out even though racked his brains. The problem was described as follow:

To a integer martix Mnn(aij), we define two function add(Mnn(aij))=Mnn(aij + 1) and sub(Mnn(aij))=Mnn(aij - 1) which were exactly like this:  According to the martix Mnn(aij), we can permutate it and get a full permutation set Perm(Mnn(aij)) = {Mnn(aIiJj)| I and J is a permutation of 1..n }, (Perm(M) is a set, each matrix in Perm(M) is unique). For example: The problem is to get the result of a fomula about an integer matrix Mnn: in which the det(M) meaned to cacluate the determinant of M.

Input

There are several test cases.

The first line contains an integer T(T ≤ 100) . Then T test cases follow.

In each test case, the first line contains one integer n(0< n≤ 10). The number means the giving matrix’s size is n×n

Then there are n lines followed, each line contains n integers aij(-10≤ aij≤ 10), in the position row i, colum j, it represents the number aij.

Output

For each test case, since the result may be very large, output one line with the result modulo 230.

Sample Input

Sample Output

Author: LIN, Binghui
Source: ZOJ Monthly, August 2014