#include <bits/stdc++.h>
using namespace std;
const int N = 4;
const int M = 100 + 5;
long long dp[2][(1 << N) + 5];
long long tdp[(1 << N) + 5];
int a[N][M];
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(dp, 0, sizeof(dp));
  int pre = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]);
  }
  for (int j = 0; j < m; ++j) {
    pre ^= 1;
    memset(dp[pre], 0, sizeof(dp[pre]));
    for (int t = 0; t < n; ++t) {
      memset(tdp, 0, sizeof(tdp));
      for (int s = 0; s < (1 << n); ++s) {
        tdp[s] = dp[pre ^ 1][s];
        for (int k = 0; k < n; ++k) {
          if ((s >> k) & 1) {
            int nk = (k + t) % n;
            tdp[s] = max(tdp[s], tdp[s ^ (1 << k)] + a[nk][j]);
          }
        }
      }
      for (int s = 0; s < (1 << n); ++s) {
        dp[pre][s] = max(dp[pre][s], tdp[s]);
      }
    }
  }
  printf("%I64d\n", dp[pre][(1 << n) - 1]);
}
int main() {
  int t;
  scanf("%d", &t);
  for (; t; --t) solve();
  return 0;
}
