Given a square binary matrix ‘mat[n][n]’, find ‘K’ such that all elements in the Kth row are ‘0’ and all elements in the Kth column are ‘1’. The value of mat[k][k] can be anything (either ‘0’ or ‘1’). If no such k exists, return ‘-1’.
Consider the following matrix :
0 1 1
0 1 0
1 1 0
You can see that row 1 (0-based) contains all 0’s except mat and column 1 contains all 1’s. Hence the answer for the above case is 1.
Input format :
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains an integer N representing the number in the problem statement.
Then N lines follow, each of which contains N space-separated integers denoting the elements of the matrix.
Output Format :
For each test case print an integer denoting the value of K if such K exists else print -1.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 5
1 <= N <= 1000
0 <= Aij <= 1
Time Limit: 1sec