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;
int T, m, n, k, s, t, bb, first[1210], ds[1210], cur[1210], deep[1210], a[1210],
    b[1210], an[1210], ss, ts, ans, tt;
struct Bn {
  int to, next, quan;
} bn[100100];
vector<int> son[1210];
queue<int> que;
inline void add(int u, int v, int w) {
  bb++;
  bn[bb].to = v;
  bn[bb].next = first[u];
  bn[bb].quan = w;
  first[u] = bb;
}
inline void ad(int u, int v, int w) {
  add(u, v, w);
  add(v, u, 0);
}
inline bool bfs() {
  int p, q;
  memset(deep, 0, sizeof(deep));
  deep[s] = 1;
  que.push(s);
  for (; !que.empty();) {
    q = que.front();
    que.pop();
    for (p = first[q]; p != -1; p = bn[p].next) {
      if (deep[bn[p].to] || !bn[p].quan) continue;
      deep[bn[p].to] = deep[q] + 1;
      que.push(bn[p].to);
    }
  }
  return deep[t];
}
int dfs(int now, int mn) {
  if (now == t) return mn;
  int res;
  for (int &p = cur[now]; p != -1; p = bn[p].next) {
    if (!bn[p].quan || deep[bn[p].to] != deep[now] + 1) continue;
    res = dfs(bn[p].to, min(bn[p].quan, mn));
    if (res) {
      bn[p].quan -= res;
      bn[p ^ 1].quan += res;
      return res;
    }
  }
  return 0;
}
int main() {
  int i, j, p, q, o, tmp;
  cin >> T;
  while (T--) {
    bb = 1, ss = ts = 0;
    memset(ds, 0, sizeof(ds));
    memset(first, -1, sizeof(first));
    memset(an, 0, sizeof(an));
    scanf("%d%d%d", &n, &m, &k);
    s = 0, t = m + n + 1;
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &p, &q);
      ad(p + m, i, 1);
      ad(q + m, i, 1);
      ds[p]++, ds[q]++;
    }
    for (i = 1; i <= m; i++) ad(i, t, 1), ts++;
    for (i = 1; i <= n; i++) {
      if (ds[i] > k) ad(s, i + m, (ds[i] - k) * 2), ss += (ds[i] - k) * 2;
    }
    if (i <= n || ss > ts) {
      for (i = 1; i <= m; i++) printf("0 ");
      puts("");
      continue;
    }
    ans = tt = 0;
    for (; bfs();) {
      for (i = 0; i <= t; i++) cur[i] = first[i];
      for (p = dfs(s, 0x3f3f3f3f); p; ans += p, p = dfs(s, 0x3f3f3f3f))
        ;
    }
    if (ans < ss) {
      for (i = 1; i <= m; i++) printf("0 ");
      puts("");
      continue;
    }
    for (i = 1; i <= n; i++) son[i].clear();
    for (i = 1; i <= m; i++) {
      for (p = first[i]; p != -1; p = bn[p].next) {
        if (bn[p].to > m && bn[p].to <= m + n && bn[p].quan) {
          son[bn[p].to - m].push_back(i);
          break;
        }
      }
    }
    for (i = 1; i <= n; i++) {
      for (j = 0; j < son[i].size(); j += 2) {
        an[son[i][j]] = an[son[i][j + 1]] = ++tt;
      }
    }
    for (i = 1; i <= m; i++) {
      if (an[i])
        printf("%d ", an[i]);
      else
        printf("%d ", ++tt);
    }
    puts("");
  }
}