Problem: Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has been installed. Unfortunately, now the questions being asked are more complicated, and even humans have trouble answering them. Can you still program the robot army to do this reliably?

The new questions are of the following form: a grayscale photograph has been divided into several horizontal pieces, which have been arbitrarily rearranged. The task is to assemble the original image back from these pieces (somewhat like in a jigsaw puzzle). To further delay the zombies, significant Gaussian-distributed noise has been added to the image.

Input

The input format is the same as in the previous version, except that the first line of every question now contains three space-separated numbers h, w and k (1 ≤ h, w ≤ 600, 2 ≤ k ≤ 16) – the height (number of rows) and width (number of columns) of the photograph and the number of pieces, respectively. The number of pieces evenly divides the height, and each piece is of the same height h / k.

Again, there is only one input file to be processed, and the same resources are provided to you as in the previous version (except that now you are given all input images in .bmp format, rather than the first 50).

Output

Your program should print q lines. The i-th line should contain your answer for the i-th question: a space-separated sequence of k numbers π1, π2, ..., πk such that: 

  * π is a permutation of {1, 2, ..., k}, that is, each number from 1 to k appears exactly once in π, 
  * for each j = 1, ..., k, πj is the position (index), in the original image, of the piece which is at position j in the input image. (See the illustration below for clarity.) 

<image>

The second image from the test set. If the three pieces in the original image are numbered 1, 2, 3 from top to bottom, then the numbering in the image on the right should be 2, 3, 1. The correct answer for this image is thus 2 3 1.

Again, your answers will be accepted if they conform to this format and if at least 75% of them are correct.

Again, you may process the input locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).

Note

The link to download all the necessary materials is http://assets.codeforces.com/files/690/medium_contestant_package.zip

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x + _y;
  if (_ >= _mod) _ -= _mod;
  return _;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x - _y;
  if (_ < 0) _ += _mod;
  return _;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x * _y;
  if (_ >= _mod) _ %= _mod;
  return _;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1ll;
  long long _tmp = mypow(_a, _x / 2, _mod);
  _tmp = mul(_tmp, _tmp, _mod);
  if (_x & 1) _tmp = mul(_tmp, _a, _mod);
  return _tmp;
}
long long mymul(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 0ll;
  long long _tmp = mymul(_a, _x / 2, _mod);
  _tmp = add(_tmp, _tmp, _mod);
  if (_x & 1) _tmp = add(_tmp, _a, _mod);
  return _tmp;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
void build() {}
inline double sqr(long long x) { return x * x; }
int r, c, k, vl[1021][1021], vd[1021][1021], po;
inline double cal(int ii, int jj) {
  int r1 = ii * po + po - 1;
  int r2 = jj * po;
  double cu = 0;
  for (int j = 0; j < c; j++) cu += sqr(vd[r1][j] - vd[r2][j]);
  return cu;
}
const double inf = 1e40;
double cst[16][16];
void init() {
  r = getint();
  c = getint();
  k = getint();
  po = r / k;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) vl[i][j] = getint();
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) {
      vd[i][j] = 0;
      int got = 0;
      for (int di = -1; di <= 1; di++)
        for (int dj = -1; dj <= 1; dj++) {
          int nxti = i + di;
          int nxtj = j + dj;
          if (nxti < 0 || nxti >= r || nxtj < 0 || nxtj >= c ||
              i / po != nxti / po)
            continue;
          vd[i][j] += vl[nxti][nxtj];
          got++;
        }
      vd[i][j] /= got;
    }
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++)
      if (i == j)
        cst[i][j] = inf;
      else
        cst[i][j] = cal(i, j);
}
double dp[16][1 << 16];
int bk[16][1 << 16];
void solve() {
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < (1 << k); j++) dp[i][j] = inf;
    dp[i][1 << i] = 0;
  }
  for (int msk = 0; msk < (1 << k); msk++)
    for (int i = 0; i < k; i++)
      if (dp[i][msk] < inf) {
        for (int j = 0; j < k; j++) {
          if ((msk >> j) & 1) continue;
          double tcst = dp[i][msk] + cst[i][j];
          if (tcst < dp[j][msk | (1 << j)]) {
            dp[j][msk | (1 << j)] = tcst;
            bk[j][msk | (1 << j)] = i;
          }
        }
      }
  double bst = inf;
  int lst = -1;
  for (int i = 0; i < k; i++)
    if (dp[i][(1 << k) - 1] < bst) {
      bst = dp[i][(1 << k) - 1];
      lst = i;
    }
  vector<int> ans, rans;
  rans.resize(k);
  int msk = (1 << k) - 1;
  for (int i = 0; i < k; i++) {
    ans.push_back(lst);
    int nxt = bk[lst][msk];
    msk ^= (1 << lst);
    lst = nxt;
  }
  reverse((ans).begin(), (ans).end());
  for (size_t i = 0; i < ans.size(); i++) rans[ans[i]] = i;
  for (int i = 0; i < k; i++) printf("%d%c", rans[i] + 1, " \n"[i + 1 == k]);
}
int main() {
  build();
  __ = getint();
  while (__--) {
    init();
    solve();
  }
}