#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int K = 24;
const int M = 5000005;
const int mod = 2017;
const int inf = int(1e9);
const long double eps = 1e-9;
int a[6][110];
int dp[110][20];
void solve() {
  int t;
  scanf("%d", &t);
  while (t-- > 0) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
      for (int j = 1; j <= m; ++j) {
        scanf("%d", &a[i][j]);
      }
    }
    for (int i = 1; i <= m; ++i) {
      for (int j = 0; j < (1 << n); ++j) {
        dp[i][j] = 0;
      }
    }
    for (int j = 1; j <= m; ++j) {
      for (int i = 0; i < (1 << n); ++i) {
        int cur = i;
        dp[j][i] = dp[j - 1][i];
        while (cur) {
          cur = i & (cur - 1);
          for (int l = 0; l < n; ++l) {
            int res = 0;
            for (int p = 0; p < n; ++p) {
              if (i & (1 << p) && !(cur & (1 << p))) {
                res += a[(p + l) % n][j];
              }
            }
            dp[j][i] = max(dp[j][i], dp[j - 1][cur] + res);
          }
        }
      }
    }
    cout << dp[m][(1 << n) - 1] << endl;
  }
}
int main() {
  solve();
  return 0;
}
