#include <bits/stdc++.h>
using namespace std;
int t, n, m, ans, k;
int a[6][111], mx[111];
vector<pair<int, int> > v;
void rec(int step, vector<int> mx) {
  if (step == k) {
    int sum = 0;
    for (int num : mx) sum += num;
    ans = max(ans, sum);
    return;
  }
  for (int j = 0; j < n; ++j) {
    vector<int> new_mx = mx;
    for (int i = 0; i < n; ++i)
      new_mx[i] = max(new_mx[i], a[(i + j) % n][v[step].second]);
    rec(step + 1, new_mx);
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    ans = 0;
    v.clear();
    cin >> n >> m;
    for (int i = 0; i < m; ++i) mx[i] = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        cin >> a[i][j];
        mx[j] = max(mx[j], a[i][j]);
      }
    for (int j = 0; j < m; ++j) v.push_back(make_pair(mx[j], j));
    sort((v).begin(), (v).end());
    reverse((v).begin(), (v).end());
    if ((int)v.size() > n) v.resize(n);
    k = (int)v.size();
    vector<int> mx(4);
    rec(0, mx);
    cout << ans << "\n";
  }
  return 0;
}
