

Both Ninja’s starting cell and the destination cell exist on an empty space, and they will not be at the same position initially.
The given maze does not contain borders (like the red rectangle in the sample pictures), but you could assume the borders of the maze are all walls.
N = 3, M = 3
Maze = [ [ 0, 0, 0 ], [ 0, 1, 0 ], [ 1, 0, 0] ]
Start = [ 0, 0 ]
Destination = [ 2, 1 ]
Explanation :
Ninja can start from (0,0) and take the right direction and run till (0,2). Then he turns direction to down and runs till (2,2). Then Ninja turns direction to the left and runs till (2,1).
The first line contains an integer 'T' which denotes the number of test cases to be run. Then the test cases follow.
The first line of each test case contains integers ‘N’ and ‘M’ representing the number of rows and columns of the maze.
The next ‘N’ line contains ‘M’ integers representing the cells of the maze. 1 represents a wall and 0 represents the empty space.
The next line contains two integers representing the coordinates of the starting position of Ninja.
The next line contains the destination coordinates.
For each test case, output an integer denoting the shortest distance required to reach from the starting position to the destination. If it is impossible to reach the destination, output -1.
Print the output of each test case in a new line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 100
1 <= M <= 100
Time Limit : 1 sec
Algorithm :