
Here, the arrows starting from the 0-cell’s point towards their corresponding nearest one cell, and among all of these, the arrow in purple and orange gives the maximum distance, i.e., 2.
1) Binary matrix of size N*M is a matrix with N rows and M columns, in which all the cells have either value 0 or 1.
2) Nearest 1-cell from a 0-cell is the cell that contains 1 and is at least a distance from the 0-cell being considered among all the other cells. For example consider the matrix {{0,1},{0,1}}. Here the nearest 1-cell for the 0-cell at index(0,0) is the 1-cell at index (0,1) because this cell is at least distance from the 0-cell being considered as the distance from the other 1-cell at index(1,1) is 2, whereas the distance from the 1-cell at index (0,1) is 1.
3) If there are no 1-cells or no 0-cells in the matrix, return -1.
The first line of the input contains an integer 'T' denoting the number of test cases. Then 'T' test cases follow:
The first line of each test case contains two space-separated integers, 'N' and 'M', where 'N' is the number of rows in the given matrix and 'M' is the number of columns in the given matrix.
Then 'N' lines follow for each test case:
Each line contains 'M' space-separated integers(either 1 or 0).
For more clarity, please refer to the sample input.
Each test case's the only line of output consists of an integer 'X', denoting the maximum possible distance from a 0-cell to its nearest 1-cell.
Output for each test case will be printed in a separate line.
You do not need to print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 100
1 <= M <= 100
where 'T' is the number of test cases, 'N' is the number of rows in the given matrix, and 'M' is the number of columns in the given matrix.
Time Limit: 1 sec.