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 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("");
  }
}