#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, k, ans;
int mp[N][N], ma[N];
int id[N], d[N], rev[N];
bool vis[N], cc[N];
void dfs(int pre) {
  if (pre >= k) {
    int res = 0;
    for (int i = 0; i < n; i++) {
      int mm = 0;
      for (int j = 0; j < k; j++) {
        mm = max(mm, mp[(i + d[j]) % n][id[j]]);
      }
      res += mm;
    }
    ans = max(ans, res);
    return;
  }
  for (int i = 0; i < n; i++) {
    d[pre] = i;
    dfs(pre + 1);
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &mp[i][j]);
      }
    }
    for (int i = 0; i < m; i++) {
      ma[i] = mp[0][i];
      for (int j = 1; j < n; j++) {
        ma[i] = max(ma[i], mp[j][i]);
      }
    }
    k = min(n, m);
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < m; j++) {
        if (vis[j]) continue;
        if (vis[id[i]] || ma[j] > ma[id[i]]) {
          id[i] = j;
        }
      }
      vis[id[i]] = true;
    }
    ans = 0;
    dfs(0);
    printf("%d\n", ans);
    for (int i = 0; i < n; i++) id[i] = 0;
    for (int j = 0; j < m; j++) vis[j] = false, ma[j] = 0;
  }
  return 0;
}
