#include <bits/stdc++.h>
using namespace std;
int t, n, m, a[200][200], dp[200][200], g[200];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    memset(dp, 0, sizeof(dp));
    for (register int i = 1; i <= n; ++i)
      for (register int j = 1; j <= m; ++j)
        scanf("%d", &a[i][j]), a[i + n][j] = a[i][j];
    for (register int j = 1; j <= m; ++j) {
      memset(g, 0, sizeof(g));
      for (int z = 0; z < (1 << n); z++) {
        for (register int s = 1; s <= n; ++s) {
          int sum = 0;
          for (register int i = s; i <= s + n - 1; ++i) {
            if (z & (1 << (i - s))) sum += a[i][j];
          }
          g[z] = max(g[z], sum);
        }
        for (int z1 = 0; z1 < (1 << n); z1++) {
          if (z1 & z) continue;
          dp[z1 | z][j] = max(dp[z1 | z][j], dp[z1][j - 1] + g[z]);
        }
      }
    }
    cout << dp[(1 << n) - 1][m] << endl;
  }
  return 0;
}
