#include <bits/stdc++.h>
using namespace std;
vector<int> masks = {0, 1, 3, 5, 7, 11, 15};
int dp[16][101];
int a[4][101];
int n, m;
int digitnum(int mask) {
  for (int temp = 6; temp >= 0; temp--) {
    if (mask & (1 << temp)) return temp + 1;
  }
  return 1;
}
int shift(int mask) {
  mask <<= 1;
  if (digitnum(mask) > n) {
    mask -= (1 << n);
    mask += 1;
  }
  return mask;
}
int solve(int mask, int pos) {
  if (pos == m) {
    if (mask == (1 << n) - 1) return 0;
    return -1 * 10e8;
  }
  int &mx = dp[mask][pos];
  if (mx != -1) return mx;
  mx = -1 * 10e8;
  for (auto coba : masks) {
    if (digitnum(coba) > n) break;
    int maxcyc = -1 * 10e8;
    for (int cyc = 0; cyc < n; cyc++) {
      int sum = 0;
      for (int temp = 0; temp < n; temp++) {
        if (coba & (1 << temp)) {
          sum += a[temp][pos];
        }
      }
      maxcyc = max(maxcyc, sum);
      coba = shift(coba);
    }
    if (maxcyc == -1 * 10e8) continue;
    for (int cyc = 0; cyc < n; cyc++) {
      if ((mask & coba) == 0) {
        mx = max(mx, solve(mask | coba, pos + 1) + maxcyc);
        break;
      }
      coba = shift(coba);
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false);
  masks.clear();
  for (int temp = 0; temp < 16; temp++) masks.push_back(temp);
  int cb = 3;
  n = 4;
  int tc;
  cin >> tc;
  while (tc--) {
    memset(dp, -1, sizeof(dp));
    cin >> n >> m;
    int temp, temp2;
    for (temp = 0; temp < n; temp++) {
      for (temp2 = 0; temp2 < m; temp2++) cin >> a[temp][temp2];
    }
    cout << solve(0, 0) << "\n";
  }
}
