#include <bits/stdc++.h>
using namespace std;
const int MAXN = 16;
const int MAXHW = 610;
const int INF = 1e8;
stack<int> sol;
int mat[MAXHW][MAXHW], adj[MAXN + 1][MAXN + 1], dp[MAXN + 1][(1 << MAXN)],
    prv[MAXN + 1][(1 << MAXN)], p[2][MAXN + 1][MAXHW], v[MAXN + 1];
int main() {
  ios::sync_with_stdio(false);
  int q, h, w, k, l1, l2, cst, aux;
  cin >> q;
  for (q; q > 0; --q) {
    cin >> h >> w >> k;
    for (int i = 0; i < h; ++i)
      for (int j = 0; j < w; ++j) cin >> mat[i][j];
    for (int i = 0; i < MAXN; ++i)
      for (int j = 0; j < (1 << MAXN); ++j) {
        dp[i][j] = INF;
        prv[i][j] = 0;
      }
    for (int i = 0; i < k; ++i) {
      l1 = i * h / k;
      l2 = l1 + h / k - 1;
      for (int j = 2; j < w - 2; ++j) {
        p[0][i][j] = (2 * mat[l1][j] + mat[l1][j + 1] + mat[l1][j - 1] +
                      mat[l1 + 1][j]) /
                     4;
        p[1][i][j] = (2 * mat[l2][j] + mat[l2][j + 1] + mat[l2][j - 1] +
                      mat[l2 - 1][j]) /
                     4;
      }
    }
    memset(adj, 0, sizeof adj);
    for (int i = 0; i < k; ++i)
      for (int j = 0; j < k; ++j)
        for (int k1 = 2; k1 < w - 2; ++k1) {
          cst = abs(p[1][i][k1] - p[0][j][k1]);
          adj[i][j] += cst * cst / 100;
        }
    for (int i = 0; i < k; ++i) dp[i][1 << i] = 0;
    for (int conf = 3; conf < (1 << k); ++conf)
      for (int i = 0; i < k; ++i)
        if ((conf & (1 << i)) && dp[i][conf]) {
          aux = (conf ^ (1 << i));
          for (int j = 0; j < k; ++j)
            if (aux & (1 << j))
              if (dp[i][conf] > dp[j][aux] + adj[j][i]) {
                dp[i][conf] = dp[j][aux] + adj[j][i];
                prv[i][conf] = j;
              }
        }
    aux = 0;
    for (int i = 1; i < k; ++i)
      if (dp[i][(1 << k) - 1] < dp[aux][(1 << k) - 1]) aux = i;
    cst = (1 << k) - 1;
    for (int i = 0; i < k; ++i) {
      sol.push(aux);
      l1 = cst;
      cst ^= (1 << aux);
      aux = prv[aux][l1];
    }
    for (int i = 0; i < k; ++i) {
      v[sol.top()] = i;
      sol.pop();
    }
    for (int i = 0; i < k; ++i) cout << v[i] + 1 << " ";
    cout << '\n';
  }
  return 0;
}
