

The first line of input contains an integer ‘T’, denoting the number of test cases. The test cases follow.
The first line contains two space-separated integers, ‘N’ and ‘M’, which denotes the number of rows and columns in the matrix ‘MAT’.
Each of the next ‘N’ lines contains ‘M’ space-separated integers denoting the 'N' tows of the matrix 'MAT'
For each test case, print a single line containing a single integer denoting the minimum total distance traveled by you and your friends.
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 <= 500
1 <= M <= 500
0 <= MAT[i][j] <= 1
Where 'T' is the number of test cases, N, M denotes the number of rows and columns in the matrix ‘MAT’, and 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 iterate over all the points and find what is the total distance traveled by all the friends if the current point is being chosen as a meeting point and select the point which gives the minimum possible distance as the meeting point.
The steps are as follows:
The idea is to store both x coordinates and y coordinates separately in an array and then find the midpoint from them, and this will be the point in which the total distance traveled will be minimum. As we are using Manhattan distance to calculate the distance between the two points and Manhattan distance, we can treat x and y coordinates separately. If we find the middle of all the x coordinates, it will be similar to the mean of all x coordinates, i.e., all the friends will have to go to the middle point which will minimize the sum of distances traveled. Similar is the case with y coordinate.
The steps are as follows: