
1. If three or more bombs with the same power are adjacent vertically or horizontally, then they blast at the same time immediately and their cells become empty.
2. After the bombs blast simultaneously if an empty cell on ‘BOMB-GRID’ has a bomb on top of itself, then these bombs will drop until they hit a bomb or hit at the bottom at the same time. (No new bombs will drop from outside of the top boundary of the ‘BOMB-GRID').
3. After the above steps, there may exist more bombs that can be blasted. If so, the above steps will be repeated.
4. If there does not exist more bombs that can be blasted (ie. the 'BOMB-GRID' is safe), then return the current ‘BOMB-GRID’.
5. The time taken by bombs to shift from one position to another can be neglected.
For the ‘BOMB-GRID’ shown below, the third grid represents a safe state i.e after all possible blasts.

The first line of input contains an integer ‘T’ denoting the number of test cases. Then each test case follows.
The first line of each test case contains two single space-separated integers ‘N’ and ‘M’ representing the number of rows and columns in ‘BOMB-GRID’, respectively.
The next ‘N’ lines of each test case contain ‘M’ single space-separated integers denoting the power of the bomb at each cell.
For each test case, print the safe state of ‘BOMB-GRID’ in a row-wise manner.
Print the output of each test case in a separate line.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 50
1 <= M <= 50
0 <= BOMB-GRID[i][j] <= 1000
Where BOMB-GRID[i][j] denotes the power of the bomb placed in the ‘i’-th row and ‘j’-th column of ‘BOMB-GRID’.
Time limit: 1 sec
The idea behind this approach is to pick all the bombs which are adjacent to 2 or more bombs horizontally or vertically and then blast them at the same time. After that, shift all the remaining bombs to the bottom-most bomb or at the bottom of ‘BOMB-GRID’ and replace the empty cells with 0s. Do this while we do not get a safe state of ‘BOMB-GRID’.
Algorithm
Do the following while we do not get a safe state of ‘BOMB-GRID’: