#include <bits/stdc++.h>
const int N = 4, M = 100;
using namespace std;
int a[N + 1][M + 1], b[N + 1][M + 1];
vector<pair<int, int>> g;
string tos(int x, int b) {
  string res = "";
  while (x) {
    res += (char)(x % b + 48);
    x /= b;
  }
  while (res.size() < b) res += '0';
  reverse(res.begin(), res.end());
  return res;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    g.clear();
    int pw = 1;
    for (int i = 1; i <= n; i++) {
      pw *= n;
      for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        g.push_back(make_pair(a[j][i], i));
      }
    }
    sort(g.begin(), g.end());
    int sz = g.size();
    int ans = 0;
    for (int i = 0; i < pw; i++) {
      string cur = tos(i, n);
      int res = 0;
      for (int i2 = 1; i2 <= n; i2++) {
        for (int j = 1; j <= m; j++) {
          b[i2][j] = a[i2][j];
        }
      }
      for (int j = 0; j < n; j++) {
        for (int k = 1; k <= cur[j] - 48; k++) {
          int col = g[sz - j - 1].second;
          for (int k2 = n - 1; k2 >= 1; k2--) {
            swap(b[k2][col], b[k2 + 1][col]);
          }
        }
      }
      for (int i2 = 1; i2 <= n; i2++) {
        int ff = 0;
        for (int j = 1; j <= m; j++) {
          ff = max(ff, b[i2][j]);
        }
        res += ff;
      }
      ans = max(ans, res);
    }
    cout << ans << endl;
  }
}
