#include <bits/stdc++.h>
int main() {
  long long int t, q, a[31][31], i, j, n, m, k, l, x, y, s, f = 0;
  scanf("%lld", &t);
  for (q = 1; q <= t; q++) {
    s = 0;
    scanf("%lld %lld", &n, &m);
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        scanf("%lld", &a[i][j]);
      }
    }
    l = (m + n - 1) / 2 - 1;
    if (n <= m) {
      for (k = 0; k <= l; k++) {
        i = 1;
        j = 1 + k;
        x = 0;
        y = 0;
        while (i <= n && j >= 1) {
          if (a[i][j] == 0) {
            x++;
          } else {
            y++;
          }
          i++;
          j--;
        }
        i = n;
        j = m - k;
        while (i >= 1 && j <= m) {
          if (a[i][j] == 0) {
            x++;
          } else {
            y++;
          }
          i--;
          j++;
        }
        if (x >= y) {
          s = s + y;
        } else {
          s = s + x;
        }
      }
    } else {
      for (k = 0; k <= l; k++) {
        i = n - k;
        j = m;
        x = 0;
        y = 0;
        while (i <= n && j >= 1) {
          if (a[i][j] == 0) {
            x++;
          } else {
            y++;
          }
          i++;
          j--;
        }
        i = 1 + k;
        j = 1;
        while (i >= 1 && j <= m) {
          if (a[i][j] == 0) {
            x++;
          } else {
            y++;
          }
          i--;
          j++;
        }
        if (x >= y) {
          s = s + y;
        } else {
          s = s + x;
        }
      }
    }
    printf("%lld\n", s);
  }
  return 0;
}
