Problem of the day
1) From any cell you can move UP, DOWN, LEFT, or RIGHT.
2) You cannot move out of the grid.
The first line of the input contains an integer 'T,’ denoting the number of test cases.
The first line of each test case contains two space-separated integers, 'N' and 'M', denoting the number of rows and columns in the grid respectively.
Each of the next 'N' lines contains 'M' space-separated integers denoting the cell values of the grid.
For each test case, print a single line containing a single integer denoting the minimum total cost that you need to spend to reach the Bottom-Right cell if you are starting from the Top-Left cell.
The output of each test case will be printed 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 <= 10
1 <= N <= 200
1 <= M <= 200
1 <= MAT[i][j] <= 10 ^ 4
Where 'MAT[i][j]' denotes the element present at the 'i'th' row and the 'j'th' column of the matrix 'MAT'.
Time limit: 1 sec.
2
3 3
1 1 1
2 2 2
3 3 3
2 2
1 3
3 4
8
8
For the first test case, the path (0,0) => (0,1) => (0,2) => (1,2) => (2,2) has the minimum total cost, i.e, 8. Hence, the answer is 8 in this case.
For the second test case, the path (0,0) => (0,1) => (1,1) has the minimum total cost, i.e, 8. Hence, the answer is 8 in this case.
2
2 5
1 5 2 1 1
1 1 1 7 2
1 4
5 3 7 1
10
16