#include <bits/stdc++.h>
using namespace std;
struct node {
  int mx, id;
  bool friend operator<(node a, node b) { return a.mx > b.mx; }
} e[110];
int a[11][110], id[5], ans;
int n, m, N;
void dfs(int pos) {
  if (pos == N + 1) {
    int t = 0;
    for (int i = 1; i <= n; ++i) {
      int tmp = 0;
      for (int j = 1; j <= N; ++j) tmp = max(tmp, a[i][id[j]]);
      t += tmp;
    }
    ans = max(ans, t);
    return;
  }
  for (int i = 1; i <= n; ++i) {
    int tmp[5] = {0};
    for (int j = 1; j <= n; ++j) tmp[j] = a[j % n + 1][id[pos]];
    for (int j = 1; j <= n; ++j) a[j][id[pos]] = tmp[j];
    dfs(pos + 1);
  }
}
void init() {
  ans = 0;
  memset(a, 0, sizeof a);
  memset(id, 0, sizeof id);
  memset(e, 0, sizeof e);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    init();
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        scanf("%d", &a[i][j]);
        e[j].id = j;
        e[j].mx = max(e[j].mx, a[i][j]);
      }
    sort(e + 1, e + 1 + m);
    N = min(n, m);
    for (int i = 1; i <= N; ++i) id[i] = e[i].id;
    dfs(1);
    printf("%d\n", ans);
  }
}
