#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 5;
int mp[maxn][maxn], dp[maxn][maxn], n, m;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(dp, 0, sizeof dp);
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) scanf("%d", &mp[i][j]);
    for (int i = 1; i <= m; i++) {
      memset(dp[i & 1], 0, sizeof dp[i & 1]);
      for (int k = 0; k < n; k++) {
        for (int s = 0; s < (1 << n); s++) {
          int tmp = 0;
          for (int j = 1; j <= n; j++) {
            if (s & (1 << (j - 1))) tmp += mp[j][i];
          }
          for (int x = 0; x < (1 << n); x++) {
            if (!(s & x))
              dp[i & 1][s | x] = max(dp[i & 1][s | x], dp[!(i & 1)][x] + tmp);
          }
        }
        for (int j = 1; j <= n; j++) mp[j - 1][i] = mp[j][i];
        mp[n][i] = mp[0][i];
      }
    }
    printf("%d\n", dp[m & 1][(1 << n) - 1]);
  }
  return 0;
}
