Problem: You are playing one famous sandbox game with the three-dimensional world. The map of the world can be represented as a matrix of size , where the height of the cell is .
You are in the cell right now and want to get in the cell . You can move only down (from the cell to the cell ) or right (from the cell to the cell ). There is an additional restriction: if the height of the current cell is then you can move only to the cell with height .
Before the first move you can perform several operations. During one operation, you can decrease the height of any cell by one. I.e. you choose some cell and assign (set) . Note that you can make heights less than or equal to zero. Also note that you can decrease the height of the cell .
Your task is to find the minimum number of operations you have to perform to obtain at least one suitable path from the cell to the cell . It is guaranteed that the answer exists.
You have to answer independent test cases.
Input Format: The first line of the input contains one integer () — the number of test cases. Then test cases follow.
The first line of the test case contains two integers and () — the number of rows and the number of columns in the map of the world. The next lines contain integers each, where the -th integer in the -th line is () — the height of the cell .
It is guaranteed that the sum of (as well as the sum of ) over all test cases does not exceed ().
Output Format: For each test case, print the answer — the minimum number of operations you have to perform to obtain at least one suitable path from the cell to the cell . It is guaranteed that the answer exists.