#include <bits/stdc++.h>
using namespace std;
long long ans;
void func(long long idx, vector<vector<long long> > v2) {
  if (idx == v2.size()) {
    long long ans1 = 0;
    for (long long i = 0; i < v2[0].size(); i++) {
      long long num1 = 0;
      for (long long j = 0; j < v2.size(); j++) {
        num1 = max(num1, v2[j][i]);
      }
      ans1 += num1;
    }
    ans = max(ans, ans1);
    return;
  }
  vector<long long> tmp;
  for (long long i = 0; i < v2[idx].size(); i++) {
    tmp.push_back(v2[idx][i]);
  }
  for (long long i = 0; i < tmp.size(); i++) {
    vector<long long> tmp1;
    for (long long j = 0; j < tmp.size(); j++) {
      tmp1.push_back(tmp[(i + j) % tmp.size()]);
    }
    v2[idx] = tmp1;
    func(idx + 1, v2);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    vector<vector<long long> > matrix;
    vector<pair<long long, pair<long long, long long> > > v1;
    ans = 0;
    set<long long> s1;
    cin >> n >> m;
    for (long long i = 0; i < n; i++) {
      vector<long long> tmp;
      for (long long j = 0; j < m; j++) {
        long long num;
        cin >> num;
        tmp.push_back(num);
        v1.push_back(make_pair(num, make_pair(i, j)));
      }
      matrix.push_back(tmp);
    }
    sort(v1.begin(), v1.end(),
         greater<pair<long long, pair<long long, long long> > >());
    long long ctr = 0;
    while (ctr < v1.size()) {
      s1.insert(v1[ctr].second.second);
      ctr++;
      if (s1.size() == min(n, m)) {
        break;
      }
    }
    vector<vector<long long> > v2;
    ans = 0;
    for (auto it : s1) {
      long long col = it;
      vector<long long> tmp;
      for (long long i = 0; i < n; i++) {
        tmp.push_back(matrix[i][col]);
      }
      v2.push_back(tmp);
    }
    func(0, v2);
    cout << ans << '\n';
  }
  return 0;
}
