#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 123, inf = (int)1e9, mod = (int)1e9 + 7;
const long long INF = (long long)1e18;
const double eps = 1e-9;
int n, m, dp[111][20], a[20][200], b[20];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
      for (int j = 1; j <= m; ++j) cin >> a[i][j];
    for (int i = 0; i <= m; ++i)
      for (int j = 0; j < (1 << n); ++j) dp[i][j] = 0;
    for (int j = 1; j <= m; ++j) {
      for (int k = 1; k <= n; ++k) {
        for (int m1 = 0; m1 < (1 << n); ++m1)
          for (int m2 = 0; m2 <= m1; ++m2)
            if ((m2 & m1) == m2) {
              int x = dp[j - 1][m2];
              for (int e = 0; e < n; ++e)
                if (((m1 >> e) & 1) && !((m2 >> e) & 1)) x += a[e][j];
              dp[j][m1] = max(dp[j][m1], x);
            }
        for (int i = 0; i + 1 < n; ++i) b[i] = a[i + 1][j];
        b[n - 1] = a[0][j];
        for (int i = 0; i < n; ++i) a[i][j] = b[i];
      }
    }
    cout << dp[m][(1 << n) - 1] << endl;
  }
  return 0;
}
