#include <bits/stdc++.h>
using namespace std;
const int size = 606;
const int block = 18;
const long long inf = 1e17;
long long dp[1 << block][block], pr[1 << block][block];
int h, w, k, data[size][size], q, ans[block];
long long diff[size][size];
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d", &h, &w, &k);
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        scanf("%d", &data[i][j]);
      }
    }
    int l = h / k;
    for (int i = 0; i < (1 << k); ++i) {
      for (int j = 0; j < k; ++j) {
        dp[i][j] = inf;
      }
    }
    for (int i = 0; i < k; ++i) {
      dp[1 << i][i] = 0;
    }
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j < k; ++j) {
        diff[i][j] = 0;
        for (int x = 0; x < w; ++x) {
          long long add = abs(data[(i * l) + (l - 1)][x] - data[j * l][x]);
          diff[i][j] += add * add * add;
          add = abs(data[(i * l) + (l - 2)][x] - data[(j * l) + 1][x]);
          diff[i][j] += add * add * add;
        }
      }
    }
    for (int i = 0; i < (1 << k); ++i) {
      for (int j = 0; j < k; ++j) {
        for (int x = 0; x < k; ++x) {
          if ((i & (1 << x)) == 0 &&
              dp[i | (1 << x)][x] > dp[i][j] + diff[j][x]) {
            dp[i | (1 << x)][x] = dp[i][j] + diff[j][x];
            pr[i | (1 << x)][x] = j;
          }
        }
      }
    }
    int best = 0, mask = (1 << k) - 1;
    for (int i = 0; i < k; ++i) {
      if (dp[mask][i] <= dp[mask][best]) {
        best = i;
      }
    }
    int cnt = 0;
    while (mask) {
      int old = best;
      ans[old] = k - cnt;
      cnt++;
      best = pr[mask][old];
      mask ^= 1 << old;
    }
    for (int i = 0; i < k; ++i) {
      printf("%d ", ans[i]);
    }
    puts("");
  }
  return 0;
}
