

1. It is impossible to move outside the matrix.
2. The starting point which is the top left corner of the matrix and the destination point which is the bottom right corner of the matrix is always empty, ie A[1][1] = A[N][M] = 0 (taking 1 based indexing).
3. By rightwards move it means you can go to A[x][y+1] from some cell A[x][y], if A[x][y+1] exists and moving to A[x][y+1] is not forbidden.
4. By downwards move it means you can go to A[x+1][y] from some cell A[x][y], if A[x+1][y] exists and moving to A[x+1][y] is not forbidden.
The first line of input contains an integer T, denoting the number of test cases.
The first line of each test case consists of two space-separated integers N and M denoting the number of rows and number of columns of the Binary Matrix A respectively.
The following N lines contain M space-separated booleans ( 0’s or 1’s) denoting the permissible and forbidden positions respectively, as described in the problem statement.
For each test case, print the number of ways to go from the top left corner to the bottom right corner of the given matrix.
You don't have to print anything, it has already been taken care of. Just Implement the given function.
1 <= T <= 10
1 <= N, M <= 1000
0 <= A[i][j] <= 1, for each cell position (i, j)
The summation of N*M for all test cases won’t exceed 10^6.
Time Limit: 1 sec
Eg. For following input binary matrix:
This algorithm works like this.
Eg. For following input binary matrix:
This algorithm works like this.