1702 - Build a Program   

Description

        Linear algebra is widely used in scientific computation. Dr. Lee wants to design a system for scientific computation research, and he needs your help. In particular, your task is to write a program to compute the determinant of a square matrix A (n-by-n matrix), which will be one of most frequently used operations in this system.

        However, the closed form of the determinant is too complex when n is greater than three. Dr. Lee suggests you to use the Laplace formula to calculate the determinant recursively. Laplace formula expresses the determinant of a matrix A in terms of its minors. The minor Mij is defined to be the determinant of the (n−1)-by-(n−1) matrix that results from A by removing the ith row and the jth column. The expression (-1)i+jMij is known as cofactor. The determinant of A, denoted by det(A), can be computed by …

        Please write a program to achieve this task.

Input

        The first line contains an integer t (1 <= t <= 20), which indicates the number of test cases in the input.

        Following that, each case starts with an integer n (2 <= n <= 8), which indicates the size of the square matrix A. Then in the next n lines, each line contains n integers, showing the entries of each row of the matrix A. The range of values in the entries is from -5 to 5.

Output

        For each case, output one line with the determinant of matrix A.

Sample Input  Download

Sample Output  Download

Tags




Discuss