#include <bits/stdc++.h>
using namespace std;
int n, m, a[13][2002], cost[2002][1 << 12];
int dp[2002][1 << 12];
void solve() {
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      cin >> a[i][j];
    }
  }
  memset(cost, 0, sizeof cost);
  for (int i = 1; i < m + 1; i++) {
    for (int j = 0; j < 1 << n; j++) {
      for (int k = 0; k < n; k++) {
        if ((j >> k) & 1) {
          cost[i][j] += a[k + 1][i];
        }
      }
    }
    for (int j = 0; j < 1 << n; j++) {
      int mx = cost[i][j], cur = j;
      for (int k = 0; k < n; k++) {
        cur = (cur >> 1) + (cur % 2) * (1 << (n - 1));
        mx = max(mx, cost[i][cur]);
      }
      cost[i][j] = mx;
    }
  }
  memset(dp, -127, sizeof dp);
  dp[0][0] = 0;
  for (int i = 1; i < m + 1; i++) {
    for (int mask = 0; mask < 1 << n; mask++) {
      dp[i][mask] = dp[i - 1][mask];
      for (int sub = mask; sub >= 0; sub = mask & (sub - 1)) {
        dp[i][mask] = max(dp[i][mask], dp[i - 1][sub] + cost[i][sub ^ mask]);
        if (sub == 0) break;
      }
    }
  }
  cout << dp[m][(1 << n) - 1] << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
