#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int maxn = 605;
int a[maxn][maxn], b[maxn][maxn];
int st[20][maxn], ed[20][maxn];
long long diff[20][20];
long long f[66000][20];
int pre[66000][20];
bool upd(long long &x, long long y) {
  if (x == -1 || y < x) return x = y, 1;
  return 0;
}
int n, m, k, ans[20], ret[20], ac;
void go(int s, int ts) {
  if (!s) return;
  go(s ^ (1 << ts - 1), pre[s][ts]);
  ans[++ac] = ts;
}
int blt[maxn];
long long sqr(int x) { return (long long)x * x; }
int main() {
  for (int T = rd(); T--;) {
    n = rd(), m = rd(), k = rd();
    for (int i = int(1); i <= (int)(n); i++)
      for (int j = int(1); j <= (int)(m); j++) a[i][j] = rd();
    for (int i = int(1); i <= (int)(k); i++)
      for (int j = int(1); j <= (int)(m); j++) {
        st[i][j] = a[n / k * (i - 1) + 1][j] + a[n / k * (i - 1) + 2][j];
        ed[i][j] = a[n / k * i][j] + a[n / k * i - 1][j];
      }
    for (int i = int(1); i <= (int)(k); i++)
      for (int j = int(1); j <= (int)(k); j++) {
        if (i == j) continue;
        long long v = 0;
        for (int k = int(1); k <= (int)(m - 4); k++) {
          int suma = 0, sumb = 0;
          for (int x = int(0); x <= (int)(4); x++)
            suma += ed[i][k + x], sumb += st[j][k + x];
          v += sqr(suma - sumb);
        }
        diff[i][j] = v;
      }
    memset(f, -1, sizeof f);
    for (int i = int(1); i <= (int)(k); i++) f[1 << i - 1][i] = 0;
    for (int i = int(1); i <= (int)((1 << k) - 1); i++)
      for (int j = int(1); j <= (int)(k); j++)
        if (~f[i][j]) {
          for (int l = int(1); l <= (int)(k); l++)
            if (!((i >> l - 1) & 1)) {
              int s = i | (1 << l - 1);
              if (upd(f[s][l], f[i][j] + diff[j][l])) pre[s][l] = j;
            }
        }
    long long mn = -1;
    int ps;
    for (int i = int(1); i <= (int)(k); i++)
      if (upd(mn, f[(1 << k) - 1][i])) ps = i;
    ac = 0;
    go((1 << k) - 1, ps);
    for (int i = int(1); i <= (int)(k); i++) ret[ans[i]] = i;
    for (int i = int(1); i <= (int)(k); i++) printf("%d ", ret[i]);
    puts("");
  }
}
