#include <bits/stdc++.h>
using namespace std;
int read() {
  int res = 0, ch, flag = 0;
  if ((ch = getchar()) == '-')
    flag = 1;
  else if (ch >= '0' && ch <= '9')
    res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
  return flag ? -res : res;
}
const int inf = 0x3f3f3f3f;
int a[100][100];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  int dis[1000][2];
  memset(dis, 0, sizeof(dis));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j]) {
        dis[i + j - 1][1]++;
      } else {
        dis[i + j - 1][0]++;
      }
    }
  }
  int num = n + m - 1, ans = 0;
  for (int i = 1; i <= num / 2; i++)
    ans = ans +
          min(dis[i][0] + dis[num - i + 1][0], dis[i][1] + dis[num - i + 1][1]);
  cout << ans << '\n';
}
signed main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
