You are given a matrix with n rows (numbered from 1 to n) and m columns (numbered from 1 to m). A number a_{i, j} is written in the cell belonging to the i-th row and the j-th column, each number is either 0 or 1.

A chip is initially in the cell (1, 1), and it will be moved to the cell (n, m). During each move, it either moves to the next cell in the current row, or in the current column (if the current cell is (x, y), then after the move it can be either (x + 1, y) or (x, y + 1)). The chip cannot leave the matrix.

Consider each path of the chip from (1, 1) to (n, m). A path is called palindromic if the number in the first cell is equal to the number in the last cell, the number in the second cell is equal to the number in the second-to-last cell, and so on.

Your goal is to change the values in the minimum number of cells so that every path is palindromic.

Input

The first line contains one integer t (1 ≤ t ≤ 200) — the number of test cases.

The first line of each test case contains two integers n and m (2 ≤ n, m ≤ 30) — the dimensions of the matrix.

Then n lines follow, the i-th line contains m integers a_{i, 1}, a_{i, 2}, ..., a_{i, m} (0 ≤ a_{i, j} ≤ 1).

Output

For each test case, print one integer — the minimum number of cells you have to change so that every path in the matrix is palindromic.

Example

Input


4
2 2
1 1
0 1
2 3
1 1 0
1 0 0
3 7
1 0 1 1 1 1 1
0 0 0 0 0 0 0
1 1 1 1 1 0 1
3 5
1 0 1 0 0
1 1 1 1 0
0 0 1 0 0


Output


0
3
4
4

Note

The resulting matrices in the first three test cases:

\begin{pmatrix} 1 & 1\\\ 0 & 1 \end{pmatrix}  \begin{pmatrix} 0 & 0 & 0\\\ 0 & 0 & 0 \end{pmatrix}  \begin{pmatrix} 1 & 0 & 1 & 1 & 1 & 1 & 1\\\ 0 & 1 & 1 & 0 & 1 & 1 & 0\\\ 1 & 1 & 1 & 1 & 1 & 0 & 1 \end{pmatrix} 
import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;

import javax.print.DocFlavor;
import java.io.*;
import java.lang.reflect.Array;
import java.net.Inet4Address;
import java.nio.charset.IllegalCharsetNameException;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;

public class Solution {
    static TreeSet<Long> set = new TreeSet<>();
    public static void main(String[] args) throws IOException{
        Reader.init(System.in);
        long h = 973303; long c  = 519683 ; long t = 866255;
        double lol = (double)(h-t) /(double) (2*t - h - c);
//        System.out.println(lol);
        t =Reader.nextInt();
//        t =1;
//        System.out.println(cnt);
        PrintWriter out = new PrintWriter(System.out);
        int i = 1;
        while (t-->0){
//            out.print("Case #" + i + ": ");
            solve(out);
            i++;
        }
        out.close();
    }
    static class Pair{
        int l , r;

        public Pair(int l, int r) {
            this.l = l;
            this.r = r;
        }
    }
    static int[][] arr;
    static int n;
    static int m;
    static int[][] dep1;
    static int[][] dep2;
    static boolean[][] v1;
    static boolean[][] v2;
    static void solve(PrintWriter out)throws IOException {
        n = Reader.nextInt();
        m = Reader.nextInt();
        arr = new int[n][m];
        for (int i = 0 ; i < n ;i ++){
            for (int j = 0 ; j <m ; j++){
                arr[i][j] = Reader.nextInt();
            }
        }
        dep1 = new int[n+m+10][2];
        dep2 = new int[n+m+10][2];
        v1 = new boolean[n][m];
        v2 = new boolean[n][m];
        dfs1(0,0,0);
        dfs2(n-1 , m-1,0);
        int ans = 0;
        for (int i = 0 ; i < (n+m-1)/2 ; i++){
            int cnt1 = dep1[i][1] + dep2[i][1];
            int cnt2 = dep1[i][0] + dep2[i][0];
//            System.out.println(cnt1 + " " + cnt2 + " " + i + " " + Math.min(cnt1,cnt2));
            ans+=Math.min(cnt1 , cnt2);
        }
        out.println(ans);


    }

    static void dfs1(int i , int j, int d){
        if (check(i,j)){
            if (v1[i][j]){
                return;
            }
            v1[i][j] = true;
//            System.out.println(i+" " + j + " " + d);
            dep1[d][arr[i][j]]++;
            dfs1(i+1,j,d+1);
            dfs1(i,j+1 , d+1);
        }
        else{
            return;
        }
    }
    static void dfs2(int i , int j, int d){
        if (check(i,j)){
            if (v2[i][j]){
                return;
            }
            v2[i][j] = true;
            dep1[d][arr[i][j]]++;
            dfs2(i-1,j,d+1);
            dfs2(i,j-1 , d+1);
        }
        else{
            return;
        }
    }
    static boolean check(int i , int j ){
        if (i<0 || j <0 || i>= n || j>=m){
            return false;
        }
        return true;
    }


    public static int stringCompare(String str1, String str2)
    {

        int l1 = str1.length();
        int l2 = str2.length();
        int lmin = Math.min(l1, l2);

        for (int i = 0; i < lmin; i++) {
            int str1_ch = (int)str1.charAt(i);
            int str2_ch = (int)str2.charAt(i);

            if (str1_ch != str2_ch) {
                return str1_ch - str2_ch;
            }
        }

        // Edge case for strings like
        // String 1="Geeks" and String 2="Geeksforgeeks"
        if (l1 != l2) {
            return l1 - l2;
        }

        // If none of the above conditions is true,
        // it implies both the strings are equal
        else {
            return 0;
        }
    }








    static int next(long[] arr, long target)
    {
        int start = 0, end = arr.length - 1;

        int ans = -1;
        while (start <= end) {
            int mid = (start + end) / 2;

            // Move to right side if target is
            // greater.
            if (arr[mid] <= target) {
                start = mid + 1;
            }

            // Move left side.
            else {
                ans = mid;
                end = mid - 1;
            }
        }
        return ans;
    }

//    static int find(int x) {
//        return parent[x] == x ? x : (parent[x] = find(parent[x]));
//    }
//    static boolean merge(int x, int y) {
//        x = find(x);
//        y = find(y);
//        if (x==y){
//            return false;
//        }
//        parent[x] = y;
//        return true;
//    }







    public static void sortbyColumn(int arr[][], int col)
    {
        // Using built-in sort function Arrays.sort
        Arrays.sort(arr, new Comparator<int[]>() {

            @Override
            // Compare values according to columns
            public int compare(final int[] entry1,
                               final int[] entry2) {

                // To sort in descending order revert
                // the '>' Operator
                if (entry1[col] > entry2[col])
                    return 1;
                else
                    return -1;
            }
        });  // End of function call sort().
    }



}


class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}
class Pair{
    int a;
    int b;

    public Pair(int a, int b) {
        this.a = a;
        this.b = b;
    }
}
class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]

    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];


        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    /* A utility function to print array of size n */
    static void printArray(int arr[])
    {
        int n = arr.length;
        for (int i=0; i<n; ++i)
            System.out.print(arr[i] + " ");
        System.out.println();
    }

    // Driver method

}

class Node implements Comparable<Node>{
    int a;
    int b;
    Node (int a , int b){
        this.a = a;
        this.b = b;
    }



    public int compareTo(Node o) {
        if ((this.a%2) == (o.a%2)){
            return (this.b - o.b);
        }
        else{
            return this.a - o.a;
        }
    }
}
class Graph
{
    int V;// No. of vertices

    //An Array of List which contains
    //references to the Adjacency List of
    //each vertex
    List <Integer> adj[];
    public Graph(int V)// Constructor
    {
        this.V = V;
        adj = new ArrayList[V];
        for(int i = 0; i < V; i++)
            adj[i]=new ArrayList<Integer>();
    }

    // function to add an edge to graph
    public void addEdge(int u,int v)
    {
        adj[u].add(v);
    }
    // prints a Topological Sort of the complete graph
    public void topologicalSort(PrintWriter out,TreeSet set)
    {
        // Create a array to store indegrees of all
        // vertices. Initialize all indegrees as 0.
        int indegree[] = new int[V];

        // Traverse adjacency lists to fill indegrees of
        // vertices. This step takes O(V+E) time
        for(int i = 0; i < V; i++)
        {
            ArrayList<Integer> temp = (ArrayList<Integer>) adj[i];
            for(int node : temp)
            {
                indegree[node]++;
            }
        }

        // Create a queue and enqueue all vertices with
        // indegree 0
        Queue<Integer> q = new LinkedList<Integer>();
        for(int i = 0;i < V; i++)
        {
            if(indegree[i]==0)
                q.add(i);
        }

        // Initialize count of visited vertices
        int cnt = 0;

        // Create a vector to store result (A topological
        // ordering of the vertices)
        Vector <Integer> topOrder=new Vector<Integer>();
        while(!q.isEmpty())
        {
            // Extract front of queue (or perform dequeue)
            // and add it to topological order
            int u=q.poll();
            topOrder.add(u);

            // Iterate through all its neighbouring nodes
            // of dequeued node u and decrease their in-degree
            // by 1
            for(int node : adj[u])
            {
                // If in-degree becomes zero, add it to queue
                if(--indegree[node] == 0)
                    q.add(node);
            }
            cnt++;
        }

        // Check if there was a cycle
        if(cnt != V)
        {
            out.println(-1);
            return ;
        }

        // Print topological order
        for(int i : topOrder)
        {
            if (set.contains((char)('A'+i))) {
                out.print((char) ('A' + i));
            }
        }
        out.println();
    }
}
// Driver program to test above functions