

GRID=[[1,1,0,1],
[1,0,0,0],
[1,1,0,1]]
X,Y= (2, 3)
ANS = 2
In 1’st sec smoke will spread to (1, 3), (3, 3), (2, 2), (2, 4)
In 2’nd sec smoke will spread to (2, 1)
The first line of input contains an integer T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains four space-separated integers ‘N’, ‘M’, ‘X’, ‘Y’, dimensions of the room and the co-ordinate of the bomb.
The next N lines of each test cases contain M space-separated integers denoting the elements of the grid.
For each test case print the minimum amount of time taken by the room to spread across all the reachable cells.
Output for each test case is printed in a separate line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N, M <= 500
1 <= X <= N
1 <= Y <=M
Time Limit: 1 sec
We will use a breadth-first search to find the cell which is reachable from the bomb and farthest from the bomb. We will start our BFS from the location at expanding to the four adjacent cells if there are not visited so far.
For each cell, we will also maintain the smallest distance from the bomb.
The algorithm will be-
This queue stores all the unprocessed cells, we will pop a cell from the queue and try to move to an adjacent cell
Ans stores the final answer
We will try to visit all the adjacent cells if the distance of adjacent cells is infinity then this cell is not visited yet
We will add the adjacent the cell to queue