
An input maze is shown below

Elizabeth is trapped in the green cell and Meliodas can enter the maze from any of the yellow cells.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains an integer ‘N’ denoting the size of the matrix.
For the next N lines, each line contains N space-separated integers, denoting the power of the cells of the maze.
For each test case, print a single containing a single integer denoting the total paths in which Meliodas can save Elizabeth. In other words, print the total number of valid paths from the corner cells to the middle cell of the maze.
The output of each test case is printed in a separate line.
You are not required to print the output explicitly, it has already been taken care of. Just implement the function and return the answer.
The maze will contain an odd number of rows and columns, i.e ‘N’ will always be odd.
1 <= T <= 5
3 <= N <= 9
0 <= DATA <= 10
where ‘T’ is the number of test cases, ‘N’ is the dimension of the maze and ‘data’ is the power of each cell of the maze.
Time limit: 1 sec.
The idea is very simple. We will check from each corner cell and recursively check if it leads to the solution or not. If yes, we will increment our number of paths by 1 else we will backtrack.
Algorithm:
Initialise an integer variable ‘totalPaths’ by 0.
For each corner, we will call a recursive function called countPathsHelper.
Algorithm for countPathsHelper:
How to mark the cells visited?
Method 1: Using extra space
Method 2: Without using extra space
Note that we can move from a cell, if its value is greater than 0. If its value is 0 or less than zero, we will simply return as we can’t move anywhere from this cell.
Firstly, store the value of the cell in a temporary variable.
To mark a cell visited, we can just set its value as 0 or -1. To unmark a cell, we will restore its value stored in the temporary variable.
This is a space-efficient method to mark a cell visited or unvisited.