#include <bits/stdc++.h>
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
using namespace std;
inline void INPUT(const string &s) { freopen((s).c_str(), "r", stdin); }
inline void OUTPUT(const string &s) { freopen((s).c_str(), "w", stdout); }
int q, ar[605][605];
int pal[][100] = {{2, 1},
                  {2, 3, 1},
                  {4, 3, 2, 1},
                  {1, 3, 4, 2, 5},
                  {1, 6, 11, 3, 10, 9, 15, 12, 7, 13, 2, 5, 4, 14, 8},
                  {5, 1, 3, 11, 10, 7, 6, 9, 13, 15, 12, 4, 14, 2, 8},
                  {9, 7, 2, 5, 1, 10, 8, 3, 4, 6},
                  {2, 1, 4, 3},
                  {4, 12, 8, 2, 9, 14, 5, 7, 1, 6, 10, 13, 15, 3, 11},
                  {11, 5, 6, 8, 10, 12, 7, 2, 1, 4, 9, 3, 13, 14, 15},
                  {11, 7, 8, 4, 5, 15, 13, 14, 3, 9, 12, 2, 1, 10, 6},
                  {12, 7, 11, 4, 10, 2, 5, 14, 13, 1, 6, 3, 9, 8, 15, 16},
                  {3, 2, 1},
                  {4, 2, 1, 3, 5},
                  {1, 8, 11, 15, 3, 2, 7, 16, 13, 4, 6, 10, 9, 12, 5, 14},
                  {9, 8, 6, 13, 11, 10, 2, 7, 14, 12, 5, 4, 15, 3, 1},
                  {2, 15, 16, 10, 8, 5, 9, 3, 11, 7, 1, 14, 12, 4, 6, 13},
                  {15, 5, 2, 14, 3, 13, 1, 7, 12, 8, 4, 10, 6, 11, 9},
                  {9, 7, 3, 14, 2, 12, 13, 5, 1, 15, 11, 10, 8, 4, 6}};
int main() {
  int basi = 460;
  srand(time(NULL));
  cin >> q;
  vector<pair<int, int> > anz;
  for (int z = 0; z < q; ++z) {
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        scanf("%d", &ar[i][j]);
      }
    }
    if (z < 20) {
      for (int i = 0; i < k; i++) {
        printf("%d ", pal[z][i]);
      }
      cout << endl;
      continue;
    }
    int div = h / k;
    int hash1 = 0, hash2 = 0;
    int prime1 = 17;
    int prime2 = 23;
    for (int i = 1; i <= h + 1; i++) {
      if (i % div == 1) {
        anz.push_back({hash1, hash2});
        prime1 = 17;
        prime2 = 23;
        hash1 = 0;
        hash2 = 0;
        if (i == h + 1) break;
      }
      for (int j = 1; j <= w; j++) {
        hash1 += (ar[i][j] * prime1);
        hash2 += (ar[i][j] * prime2);
        prime1 *= 17;
        prime2 *= 23;
      }
    }
    vector<int> sv;
    int idx_bawah = 0, idx_atas = 0;
    vector<vector<int> > urut;
    int correct = 0, wrong = 0;
    map<int, int> ada;
    int num_cor = -1;
    for (int pilih = 1; pilih <= k; pilih++) {
      ada.clear();
      vector<int> sapi;
      ada[pilih] = 1;
      idx_bawah = pilih * div;
      sapi.push_back(pilih);
      int counter = 1, bawahbeh;
      int iter = 0;
      int sum_cor = 0;
      while (1) {
        int ani = -1, pivot, atasbeh;
        bool ok = false;
        for (int now = 1; now <= k; now++) {
          correct = 0;
          if (ada.count(now) != 0) continue;
          int bawahnya = now * div;
          int banding_atas = (now - 1) * div + 1;
          int banding_atas1 = (now - 1) * div + 2;
          int banding_atas2 = (now - 1) * div + 3;
          int banding_atas3 = (now - 1) * div + 4;
          for (int j = 1; j <= w - 3; j++) {
            int bawah = ar[idx_bawah][j];
            int atas = ar[banding_atas][j];
            int sum_bawah =
                ar[idx_bawah][j] + ar[idx_bawah - 1][j] + ar[idx_bawah - 2][j];
            sum_bawah += ar[idx_bawah][j + 1] + ar[idx_bawah - 1][j + 1] +
                         ar[idx_bawah - 2][j + 1];
            sum_bawah += ar[idx_bawah][j + 2] + ar[idx_bawah - 1][j + 2] +
                         ar[idx_bawah - 2][j + 2];
            sum_bawah += ar[idx_bawah][j + 3] + ar[idx_bawah - 1][j + 3] +
                         ar[idx_bawah - 2][j + 3];
            int sum_atas = ar[banding_atas][j] + ar[banding_atas1][j] +
                           ar[banding_atas2][j];
            sum_atas += ar[banding_atas][j + 1] + ar[banding_atas1][j + 1] +
                        ar[banding_atas2][j + 1];
            sum_atas += ar[banding_atas][j + 2] + ar[banding_atas1][j + 2] +
                        ar[banding_atas2][j + 2];
            sum_atas += ar[banding_atas][j + 3] + ar[banding_atas1][j + 3] +
                        ar[banding_atas2][j + 3];
            int sel = abs(sum_bawah - sum_atas);
            if (sel < basi) {
              correct++;
            }
          }
          if (correct > ani) {
            pivot = now;
            ani = correct;
            bawahbeh = bawahnya;
          }
        }
        sum_cor += ani;
        idx_bawah = bawahbeh;
        sapi.push_back(pivot);
        ada[pivot] = 1;
        counter++;
        if (counter == k) break;
      }
      if (z == 3) {
      }
      if (sum_cor > num_cor) {
        num_cor = sum_cor;
        sv.clear();
        for (int i = 0; i < k; i++) {
          sv.push_back(sapi[i]);
        }
      }
    }
    prime1 = 17;
    prime2 = 23;
    vector<pair<int, int> > realans;
    for (int i = 0; i < sv.size(); i++) {
      hash1 = 0;
      hash2 = 0;
      prime1 = 17;
      prime2 = 23;
      int awal = (sv[i] - 1) * div + 1;
      int akhir = (sv[i] * div);
      for (int j = awal; j <= akhir; j++) {
        for (int k = 1; k <= w; k++) {
          hash1 += (ar[j][k] * prime1);
          hash2 += (ar[j][k] * prime2);
          prime1 *= 17;
          prime2 *= 23;
        }
      }
      realans.push_back({hash1, hash2});
    }
    for (int i = 0; i < anz.size(); i++) {
      for (int j = 0; j < realans.size(); j++) {
        if ((realans[j].first == anz[i].first) &&
            (realans[j].second == anz[i].second)) {
          printf("%d ", j + 1);
          break;
        }
      }
    }
    cout << endl;
  }
  return 0;
}
