#include <bits/stdc++.h>
using namespace std;
int dp[105][20];
int st[20][5];
int temp[20][5];
int bod[105][5], n, m;
void rot(int a) {
  int i, j, k;
  for (i = 1; i <= n; i++) {
    bod[a][i - 1] = bod[a][i];
  }
  bod[a][n] = bod[a][0];
}
int main() {
  int T, i, j, k, a, b, c, s;
  scanf("%d", &T);
  for (i = 1; i <= T; i++) {
    scanf("%d%d", &n, &m);
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= m; k++) {
        scanf("%d", &bod[k][j]);
      }
    }
    for (k = 1; k <= m; k++) {
      for (j = 1; j < (1 << n); j++) {
        dp[k][j] = 0;
      }
    }
    for (k = 1; k <= (1 << n); k++) {
      for (j = 1; j <= n; j++) st[k][j] = 0;
    }
    for (j = 1; j <= m; j++) {
      for (k = 1; k < (1 << n); k++) {
        for (a = 1; a <= k; a++) {
          if ((a & k) != a) continue;
          for (b = 1; b <= n; b++) {
            rot(j);
            s = 0;
            for (c = 0; c < n; c++) {
              if ((k & (1 << c)) == 0) continue;
              s += max(st[a][c + 1], bod[j][c + 1]);
            }
            if (s > dp[j][k]) {
              for (c = 1; c <= n; c++) {
                temp[k][c] = max(bod[j][c], st[a][c]);
              }
              dp[j][k] = s;
            }
          }
        }
      }
      for (k = 1; k < (1 << n); k++) {
        for (a = 1; a <= n; a++) {
          st[k][a] = temp[k][a];
        }
      }
    }
    printf("%d\n", dp[m][(1 << n) - 1]);
  }
}
