


You need to make the modifications in the input matrix.
You do not need to print anything, it has already been taken care of.
The first line of input contains an integer 'T' representing the number of test cases. Then the test cases follow.
The first line of each test case contains two single-spaced integers N and M, representing the number of rows and columns of the matrix respectively.
The next N line contains M single-spaced elements (0 or 1).
For each test case, the modified matrix is printed.
The output for each test case is in a separate line.
1 <= T <= 10
1 <= N, M <= 200
Where N and M are the number of rows and columns respectively.
The main idea behind this approach is that we use two temporary arrays, row[N] and col[M], to keep a track of the rows and columns which should be set to 1. Initially, both the arrays are initialized as 0.
Now, we traverse the given matrix and whenever we find a cell Mat[i][j] with value 1, we set row[i] = 1 and col[j] = 1.
After this traversal, we again traverse the given matrix and for each cell Mat[i][j], we check if either of row[i] or col[j] is 1. If either of the two values is 1, we set the value of the cell in the given matrix to 1.
The idea behind this approach is to make the solution space efficient by using the first cell of every row and column as a flag. This flag would determine whether the row or column should be set to 1. The algorithm for this approach is as follows :
// Since first cell for both first row and first column is the same i.e. matrix[0][0]
// We can use an additional variable setCol for the first column.
if (Mat[i][0] == 1) {
isCol = true;
}
for (int j = 1; j < M; j++) {
// If an element is 1, we set the first element of the corresponding row and column to 0
if (Mat[i][j] == 1) {
Mat[0][j] = 1;
Mat[i][0] = 1;
}
}
}