

1. Each element in the matrix 'MAT' is either a ‘0’ or ‘1.’
2. The flip operation is performed only for the 0s in the original matrix, and not for the new 0s formed as a result of flipping 1s in the original matrix.
3. If a cell is already flipped, don’t flip it twice.
4. Return the minimum number of flips needed.
Let the matrix be:

Then we return 6. As shown in the figure, the cells marked in red will be counted as they lie in the same row or column as 0 and will be flipped.

The first line of input contains ‘T’ denoting the number of test cases.
The first line of each test case contains ‘N’ denoting the dimensions of the ‘N * N’ matrix.
The next ‘N’ lines contain ‘N’ single space-separated integers denoting the matrix 'MAT’.
For each test case, print a single line that contains an integer that denotes the total number of flips made.
You don't have to print the output it has been taken care of. Just implement the given function.
1 <= T <= 5
0 <= N <= 100
MAT[i][j] = 0 or 1
Where ‘T’ is the number of test cases and ‘N’ is the number of rows and columns of the matrix 'MAT'.
Time limit: 1 sec
The main idea is to count the number of 1s in the same row or column as any of the 0 in the given matrix. To do that, we iterate through the matrix with the variable ‘i’ for the row and ‘j’ for the column, and if for any cell ‘MAT’[i][j] = 0, we iterate through the ‘i’th row and ‘j’th column and count the number of 1s in them and mark them as -1 so that we do not revisit them. Finally, we return the ‘COUNT’.
The main idea is to ensure that a particular row or column is already checked, we need not check it again. We can do this by maintaining a visited array for rows and columns and checking every time we encounter a ‘0’ that if its row or column is already visited then we need not check it again.
Keeping the above idea in mind, we can have the following approach:
The main idea is to calculate the number of zeros in the matrix, the number of rows that have zero, and the number of columns that have zeros.
Then the final answer = (ROWS * N) + ((N - ROWS) * COLS) - ZEROES.