#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int ntest, n, m, a[4][101], dp[101][16];
  cin >> ntest;
  while (ntest--) {
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
      for (int j = 1; j <= m; ++j) cin >> a[i][j];
    for (int i = 0; i <= m; ++i) fill(dp[i], dp[i] + (1 << n), 0);
    for (int i = 1; i <= m; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 1; k < n; ++k) swap(a[k][i], a[k - 1][i]);
        for (int k = 0; k < (1 << n); ++k) {
          int sum = 0;
          for (int r = 0; r < n; ++r)
            if ((1 << r) & k) sum += a[r][i];
          for (int l = 0; l < (1 << n); ++l) {
            if ((l & k) == 0)
              dp[i][k | l] = max(dp[i][k | l], dp[i - 1][l] + sum);
          }
        }
      }
    }
    cout << dp[m][(1 << n) - 1] << '\n';
  }
  return 0;
}
