#include <bits/stdc++.h>
using namespace std;
const int MAXR = 12;
const int MAXC = 2005;
int a[MAXR][MAXC];
int cur[1 << MAXR];
int hiBit[1 << MAXR];
int each[MAXC][1 << MAXR];
int n, m, cs;
int vis[MAXC][1 << MAXR];
int dp[MAXC][1 << MAXR];
int Solve(int col, int mask) {
  if (col == m) return 0;
  if (mask + 1 == (1 << n)) return 0;
  if (vis[col][mask] == cs) return dp[col][mask];
  vis[col][mask] = cs;
  int rem = ((1 << n) - 1) ^ (mask);
  int ret = Solve(col + 1, mask);
  for (int s = rem; s; s = (s - 1) & rem) {
    ret = max(ret, each[col][s] + Solve(col + 1, mask | s));
  }
  return dp[col][mask] = ret;
}
int main() {
  for (int msk = 1; msk < (1 << MAXR); msk++)
    hiBit[msk] = 31 - __builtin_clz(msk);
  int t;
  scanf("%d", &t);
  for (cs = 1; cs <= t; cs++) {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
    memset(each, 0, sizeof(each));
    for (int col = 0; col < m; col++) {
      for (int rot = 0; rot < n; rot++) {
        for (int msk = 1; msk < (1 << n); msk++) {
          int h = hiBit[msk];
          cur[msk] = cur[msk ^ (1 << h)] + a[(rot + h) % n][col];
          each[col][msk] = max(each[col][msk], cur[msk]);
        }
      }
    }
    printf("%d\n", Solve(0, 0));
  }
}
