Problem D: Escaping Jail

Time Limit: 1s

In a jail, some pairs of prisoners are chained together to make it more difficult for them to escape. A group of prisoners has decided to escape, and one important part of their plan is pressing two distant buttons simultaneously. They must determine the two prisoners best suited for this task.

Given the configuration of chains between prisoners, you are to calculate the maximum distance that can be achieved between two prisoners.

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. T consecutive test cases follow.

For each case, there is an integer N (2 <= N <= 50), represents the number of prisoners. Then N lines follow, each containing N integers. The ith number in the jth line (we call it Lij , -1 <= Lij <= 64) represents the length of the chain between prisoners i and j. Lij == -1 means there is no chain between that pair of prisoners, otherwise there is a chain of length Lij between that pair of prisoners. Note that Lij will always equal to Lji and Lii will always equal to 0.

Output

For each test case, output one line with the maximum distance that can be achieved between two prisoners. If there is no limit to that distance, print -1.

Sample Input

3
4
0 5 6 8
5 0 9 4
6 9 0 3
8 4 3 0
2
0 -1
-1 0
2
0 0
0 0

Sample Output

8
-1
0

Hint

For Sample 1, prisoners 1 and 2 are chained with length 9. However, they are both also chained to prisoner 3 with chains of length 3 and 4 respectively, so they cannot stand more than 7 feet apart. Prisoners 0 and 3, on the other hand, can stand 8 feet apart without trouble.

For Sample 2, both prisoners are completely unchained, so there is no limit to their distance.