#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n, x, m, i, flag = 0, a, b, l, r, sum = 2, ones = 0, zero = 0,                             output = 0, j;       vector<pair<long long, long long> > v;       cin >> n >> m;       long long arr[n + 1][m + 1];       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           cin >> arr[i][j];         }       }       a = 0;       sum = 2;       flag = 0;       while (flag == 0) {         for (i = 1; i <= n; i++) {           for (j = 1; j <= m; j++) {             if ((i + j == sum) || (i + j == n + m - a))               v.push_back(make_pair(i, j));           }         }         while (v.size() > 0) {           i = v[v.size() - 1].first;           j = v[v.size() - 1].second;           if (arr[i][j] == 0)             zero++;           else             ones++;           v.pop_back();         }         output = output + min(zero, ones);         zero = 0;         ones = 0;         a++;         sum++;         if (sum == n + m - a)           break;         else if (sum > (n + m - a))           break;       }       cout << output <<   n ;     }     return 0;   }   