#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    vector<int> dp(1 << n, -1);
    dp[0] = 0;
    for (int j = 0; j < m; j++) {
      vector<int> here(1 << n, -1);
      for (int shift = 0; shift < n; shift++) {
        for (int k = 0; k < (1 << n); k++) {
          int sum = 0;
          for (int i = 0; i < n; i++) {
            if (k & (1 << i)) sum += a[(shift + i) % n][j];
          }
          here[k] = max(here[k], sum);
        }
      }
      for (int k = (1 << n) - 1; k >= 0; k--) {
        int nt = (1 << n) - 1 - k;
        int u = nt;
        while (u > 0) {
          if (dp[k] != -1) {
            dp[k | u] = max(dp[k | u], dp[k] + here[u]);
          }
          u = (u - 1) & nt;
        }
      }
    }
    cout << dp[(1 << n) - 1] << '\n';
  }
}
