You are given an n \times n grid consisting of integers. Abed asks you to determine whether the grid is Beautiful. A grid is considered Beautiful if and only if there is at least one contiguous segment of elements of the main or secondary diagonal, the sum of which is equal to the sum of at least one row or column.
We consider only a whole row or a whole column, and any segment of the diagonals (main or secondary). For example:
Consider the following 3 \times 3 grid:
The grid is Beautiful because we can match the sub-diagonal (in blue) with the first row. Note that we used here twice.
You can choose the sub-diagonal (blue) and the row/column (red) as follows:
We will call a sub-diagonal any contiguous segment of the main diagonal elements (from to ) or the secondary diagonal (from to ).
The first line contains a single integer (1 \le t \le 10) – the number of input data sets.
The first line of each input data set contains a single integer (1 \le n \le 500) – the size of the square grid.
The next lines contain the -th row of the grid, in other words, row has a_{i,1},a_{i,2},\ldots,a_{i,n}, (1 \le a_{i,j} \le 100) – integers of the grid.
For each input data set, if the grid is Beautiful, print "YES"; otherwise, print "NO".
You may print the answer in any case (for example, strings "yEs", "yes", "Yes", and "YeS" will all be recognized as positive answers).
Example 1
For the first input data set, the sum of the left diagonal is equal to the sum of the first column, which is 1+3=4.
For the second input data set, no sub-diagonal, neither left nor right, matches the sum of any column or row.
For the third input data set, it is possible to pick from the left diagonal and match it with the sum of the first row.
Subtask ( points) : (n=2).
Subtask ( points) : (n=3).
Subtask ( points) : (n \le 10)
Subtask ( points) : (n \le 30)
Subtask ( points) : No additional restrictions.