9047 - Determinant of A Matrix   

Description

Given an n×n matrix A,

                                                                                   ,

its determinant can be defined recursively as follows.

                                                                                   

where M­1,j is an (n–1)×(n–1) matrix, defined by removing the first row and the jth column of A,

                                                                                   

For example,

                                                                                  

                                                                                  
.

Input


The first line contains an integer t (1 <= t <= 20), which indicates the number of test cases in the input. Each case starts with an integer n (2 <= n <= 8), specifying the size of the square matrix A. Then following next n lines, each line containing n integers, define the entries 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