


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.
The idea is to convert this problem as a graph problem. Each cell of the grid can be considered as a graph vertex and their costs can be considered as the weight of the vertices. We will add unweighted edges between all the pairs of adjacent cells. Using the above observations, the problem can be simplified to finding the shortest path between the Top-Left cell and Bottom-Right cell. This can be done efficiently with the help of the Dijkstra algorithm. Note that we do not need to explicitly build a graph, as we will be using the fact that for a particular cell, all edges from it exist with its adjacent cells only.