#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
int a[10][105];
struct Node {
  int dat, i, j;
};
Node b[105 * 10];
int n, m;
bool cmp(Node x, Node y) { return x.dat > y.dat; }
bool used[105];
int ans;
void dfs(int dep, int id) {
  if (dep == n + 1) {
    int res = 0;
    for (int i = 1; i <= n; i++) {
      int tmp = 0;
      for (int j = 1; j <= m; j++) {
        if (a[i][j] > tmp) tmp = a[i][j];
      }
      res += tmp;
    }
    if (res > ans) ans = res;
    return;
  }
  int now = id;
  while (m > now && used[b[now].j] == true) now++;
  if (now == m + 1) {
    dfs(n + 1, 0);
    return;
  }
  used[b[now].j] = true;
  for (int i = 1; i <= n; i++) {
    dfs(dep + 1, now + 1);
    int t = a[n][b[now].j];
    for (int j = n; j >= 2; j--) {
      a[j][b[now].j] = a[j - 1][b[now].j];
    }
    a[1][b[now].j] = t;
  }
  used[b[now].j] = 0;
}
void work() {
  cin >> n >> m;
  ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = read();
      b[(i - 1) * m + j].dat = a[i][j];
      b[(i - 1) * m + j].i = i, b[(i - 1) * m + j].j = j;
    }
  }
  sort(b + 1, b + n * m + 1, cmp);
  dfs(1, 1);
  cout << ans << endl;
}
signed main() {
  int T = read();
  while (T--) work();
  return 0;
}
