We've known quite a lot about the determinant of an matrix from linear algebra course and we now take a review
in which is the set of permutations of , and
Now given an matrix , define as the remaining submatrix after deleting the row and the line of . For example, assume , then , , .
Your task is to compute the determinant of for any modulo .
The first line contains an integer , indicating the number of matrices.
Then matrices follow. For each matrix , the first line contains an integer indicating the size of .
The following lines give the matrix. The line contains non-negative integers less than separated by a space, describing the row of the matrix.
The input guarantees that and , and the number of matrices with is no more than 3.
For each input matrix, output an matrix , in which modulo . Output an extra empty line at the end of each output matrix.
3 2 4 6 2 3 3 1 0 2 0 1 0 0 0 1 3 1 1 1 2 3 4 0 0 1
3 2 6 4 1 0 0 0 1 0 998244351 0 1 3 2 0 1 1 0 1 2 1