Problem: There are n cities and m two-way roads in Berland, each road connecting two distinct cities.

Recently the Berland government has made a tough decision to transfer ownership of the roads to private companies. In total, there are 100500 private companies in Berland, numbered by integers from 1 to 100500. After the privatization, every road should belong to exactly one company.

The anti-monopoly committee demands that after the privatization each company can own at most two roads. The urbanists of Berland also stated their opinion: each city should be adjacent to the roads owned by at most k companies.

Help the government to distribute the roads between the companies so that both conditions are satisfied. That is, each company gets at most two roads, and each city has roads of at most k distinct companies adjacent to it.

Input

Input contains one or several test cases. The first line contains an integer t (1 ≤ t ≤ 300) — the number of test cases in the input. Solve test cases separately, test cases are completely independent and do not affect each other.

The following lines describe the test cases. Each case starts with a line consisting of three space-separated integers n, m and k (2 ≤ n ≤ 600, 1 ≤ m ≤ 600, 1 ≤ k ≤ n - 1) — the number of cities, the number of roads and the maximum diversity of the roads adjacent to a city.

Then m lines follow, each having a pair of space-separated integers a_i, b_i (1 ≤ a_i, b_i ≤ n; a_i ≠ b_i). It means that the i-th road connects cities a_i and b_i. All roads are two-way. There is at most one road between a pair of the cities.

The sum of n values for all test cases doesn't exceed 600. The sum of m values for all test cases doesn't exceed 600.

Output

Print t lines: the i-th line should contain the answer for the i-th test case. For a test case, print a sequence of integers c_1, c_2, ..., c_m separated by space, where c_i (1 ≤ c_i ≤ 100500) is the company which owns the i-th road in your plan. If there are multiple solutions, output any of them. If there is no solution for a test case, print c_1=c_2=…=c_m=0.

Example

Input

3
3 3 2
1 2
2 3
3 1
4 5 2
1 2
1 3
1 4
2 3
2 4
4 6 2
1 2
1 3
1 4
2 3
2 4
3 4


Output

1 2 3 
2 1 1 2 3 
0 0 0 0 0 0 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct ISAP {
  int NE, vs, vt, NV;
  static const int N = 2e3 + 10;
  static const int M = 4e5 + 10;
  int head[N], pre[N], cur[N], level[N], gap[N];
  int V[M], nxt[M];
  long long C[M];
  void init() {
    NE = 0;
    for (int i = 0; i < NV; ++i) head[i] = -1;
  }
  void add(int u, int v, long long cap) {
    V[NE] = v;
    C[NE] = cap;
    nxt[NE] = head[u];
    head[u] = NE++;
    V[NE] = u;
    C[NE] = 0;
    nxt[NE] = head[v];
    head[v] = NE++;
  }
  long long SAP() {
    for (int i = 0; i < NV; ++i)
      cur[i] = head[i], pre[i] = -1, level[i] = gap[i] = 0;
    int u = pre[vs] = vs;
    long long maxflow = 0, aug = -1;
    gap[0] = NV;
    while (level[vs] < NV) {
      bool flag = 0;
      for (int &i = cur[u]; ~i; i = nxt[i]) {
        int v = V[i];
        if (C[i] && level[u] == level[v] + 1) {
          aug == -1 ? aug = C[i] : aug = min(aug, C[i]);
          pre[v] = u;
          u = v;
          if (v == vt) {
            maxflow += aug;
            for (u = pre[u]; v != vs; v = u, u = pre[u]) {
              C[cur[u]] -= aug;
              C[cur[u] ^ 1] += aug;
            }
            aug = -1;
          }
          flag = 1;
          break;
        }
      }
      if (flag) continue;
      int minlevel = NV;
      for (int i = head[u]; ~i; i = nxt[i]) {
        int v = V[i];
        if (C[i] && minlevel > level[v]) {
          cur[u] = i;
          minlevel = level[v];
        }
      }
      gap[level[u]]--;
      if (gap[level[u]] == 0) break;
      level[u] = minlevel + 1;
      gap[level[u]]++;
      u = pre[u];
    }
    return maxflow;
  }
} sap;
int ans[605], deg[605];
vector<int> G[605];
int main() {
  int T, n, m, k;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d", &n, &m, &k);
    sap.vs = 0;
    sap.vt = n + m + 1;
    sap.NV = sap.vt + 1;
    sap.init();
    bool flag = 1;
    for (int i = 1; i <= n; ++i) deg[i] = 0, G[i].clear();
    for (int i = 1; i <= m; ++i) {
      ans[i] = 0;
      int a, b;
      scanf("%d%d", &a, &b);
      sap.add(a, n + i, 1);
      sap.add(b, n + i, 1);
      deg[a]++;
      deg[b]++;
    }
    int aim = 0;
    for (int i = 1; i <= n; ++i) {
      if (deg[i] > 2 * k) {
        flag = 0;
      } else
        aim += 2 * max(0, (deg[i] - k));
    }
    if (!flag) {
      for (int i = 1; i <= m; ++i) printf("0%c", (i == m) ? '\n' : ' ');
      continue;
    }
    for (int i = 1; i <= n; ++i) sap.add(sap.vs, i, 2 * max(0, (deg[i] - k)));
    for (int i = 1; i <= m; ++i) sap.add(n + i, sap.vt, 1);
    if (sap.SAP() != aim) {
      for (int i = 1; i <= m; ++i) printf("0%c", (i == m) ? '\n' : ' ');
      continue;
    }
    for (int i = 0; i < 4 * m; i += 2)
      if (sap.C[i] == 0) G[sap.V[i ^ 1]].push_back(sap.V[i] - n);
    int cnt = 1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < G[i].size(); ++j) {
        ans[G[i][j]] = cnt;
        if (j & 1) cnt++;
      }
    }
    for (int i = 1; i <= m; ++i)
      if (!ans[i]) ans[i] = cnt++;
    for (int i = 1; i <= m; ++i) printf("%d%c", ans[i], (i == m) ? '\n' : ' ');
  }
  return 0;
}