#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 111, K = 20;
const int mod = 998244353, mod2 = 1e9 + 9;
const int MX = 2760131;
int arr[4][101];
int n, m;
vector<pair<int, int> > col;
int cal(vector<int> grid, int lvl) {
  if (lvl == min(n, m)) {
    int sum = 0;
    for (int i = 0; i < n; i++) sum += grid[i];
    return sum;
  }
  int idx = col[lvl].second;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    vector<int> copy = grid;
    for (int j = 0; j < n; j++) {
      int val = arr[(i + j) % n][idx];
      copy[j] = max(copy[j], val);
    }
    mx = max(mx, cal(copy, lvl + 1));
  }
  return mx;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) scanf("%d", &arr[i][j]);
    col.clear();
    col.resize(m);
    for (int j = 0; j < m; j++) {
      int mx = 0;
      for (int i = 0; i < n; i++) {
        mx = max(mx, arr[i][j]);
      }
      col[j] = make_pair(mx, j);
    }
    sort(col.rbegin(), col.rend());
    vector<int> emp(n);
    printf("%d\n", cal(emp, 0));
  }
}
