Yalikesi just took a trip to Hillington, a city so hilly that you're either walking uphill or downhill, with no in-between! Being an avid land surveying fan, Yalikesi brought his equipment to create an elevation map of the city, but limited time meant he was only able to calculate the elevation at a few locations.
Hillington can be represented by a $$$n$$$-by-$$$n$$$ grid. The tile in the $$$i$$$-th row and $$$j$$$-th column of the grid has an integer height, denoted $$$h_{i,j}$$$. For each cell, Yalikesi either knows the exact value of its height, or has not measured it yet.
A valid completion of Yalikesi's observations is a $$$n$$$-by-$$$n$$$ grid, denoted $$$a$$$, satisfying both the following:
Note that $$$a_{i,j}$$$ does not necessarily have to be positive.
A cell $$$(i,j)$$$ is said to be uniquely determined if the integer in it is the same across all valid completions.
You need to find all uniquely determined cells in $$$h$$$, and report the integers in them.
Input consists of multiple tests. The first line contains $$$t$$$, the number of tests ($$$1 \le t \le 10^4$$$).
The first line of each test contains $$$n$$$, the size of the grid ($$$1 \le n \le 500$$$).
The next $$$n$$$ lines contain $$$n$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line, which we denote $$$b_{i,j}$$$, represents the value of $$$h_{i,j}$$$.
Note that $$$h_{i,j}$$$ for unmeasured cells do not have to be positive, and may be greater than $$$10^9$$$.
It is guaranteed the sum of $$$n^2$$$ over all tests does not exceed $$$250\,000$$$.
It is guaranteed that at least one valid completion exists, and that the height of at least one cell is known.
For each test, output $$$n$$$ lines containing $$$n$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line represents the cell $$$(i,j)$$$. If it is uniquely determined, output its height. Otherwise, output 0.
We can show that under the constraints of the problem, any uniquely determined cell will have a nonzero value.
Note that in the sample tests, a newline is printed between test cases. This is only for ease of reading, and you do not need it in your solution.
550 0 0 0 00 0 0 6 00 0 0 0 03 0 0 0 00 1 0 0 0199932 1 21 0 12 1 260 8 9 8 7 88 7 8 9 8 79 8 0 8 0 88 7 6 7 8 90 6 7 8 9 00 7 6 7 8 02999999999 10000000001000000000 0
0 0 0 0 0 0 4 5 6 0 0 3 4 5 0 3 2 3 4 0 2 1 2 3 0 999 2 1 2 1 0 1 2 1 2 0 8 9 8 7 8 8 7 8 9 8 7 9 8 7 8 0 8 8 7 6 7 8 9 7 6 7 8 9 0 0 7 6 7 8 0 999999999 1000000000 1000000000 0
In the first test, here are two possible valid completions of the grid:
Note that the cells in red are all different between the two grids, therefore they cannot be uniquely determined.
In this case, it also happens that the rest of the cells are the same across all valid completions, so they are uniquely determined.
In the second case, note that the grid may already have all heights measured.
In the third case, the square in the center can be either $$$0$$$ or $$$2$$$. $$$a_{i,j}$$$ does not necessarily have to be positive, so this square is not uniquely determined.
| Name |
|---|


