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;
const int N = 200000;
const int INF = 1000000000;
class Dinic {
 private:
  int lt[N], nt[N], bi[N], tl;
  int nw[N], dis[N], vis[N];
  queue<int> Q;

 public:
  int s, e, tot, ci[N];
  int oppo(int t) { return t & 1 ? t + 1 : t - 1; }
  int add_edge(int a, int b, int c) {
    nt[++tl] = lt[a];
    lt[a] = tl;
    bi[tl] = b;
    ci[tl] = c;
    nt[++tl] = lt[b];
    lt[b] = tl;
    bi[tl] = a;
    ci[tl] = 0;
    return tl;
  }
  void flow(int p, int d) {
    ci[p] -= d;
    ci[oppo(p)] += d;
  }
  int dfs(int t, int maxl) {
    int nowl = 0;
    if (t == e) return maxl;
    for (int &p = nw[t]; p; p = nt[p])
      if (dis[t] + 1 == dis[bi[p]] && ci[p]) {
        int d = dfs(bi[p], min(ci[p], maxl - nowl));
        flow(p, d);
        nowl += d;
        if (nowl == maxl) return maxl;
      }
    return nowl;
  }
  void bfs() {
    for (int i = 1; i <= tot; ++i) vis[i] = 0, dis[i] = tot + 1;
    vis[s] = 1;
    dis[s] = 0;
    Q.push(s);
    while (!Q.empty()) {
      int hd = Q.front();
      Q.pop();
      for (int p = lt[hd]; p; p = nt[p])
        if (!vis[bi[p]] && ci[p]) {
          vis[bi[p]] = 1;
          dis[bi[p]] = dis[hd] + 1;
          Q.push(bi[p]);
        }
    }
  }
  int solve() {
    int ans = 0;
    while (1) {
      bfs();
      if (!vis[e]) return ans;
      for (int i = 1; i <= tot; ++i) nw[i] = lt[i];
      ans += dfs(s, INF);
    }
  }
  void init() {
    for (int i = 1; i <= tot; ++i) lt[i] = 0;
    for (int i = 1; i <= tl; ++i) bi[i] = ci[i] = nt[i] = 0;
    s = e = tot = tl = 0;
  }
} F;
int T, n, m, k;
int ai[N], bi[N], av[N], bv[N], cnt[N], now[N], val, tot;
int main() {
  scanf("%d", &T);
  while (T--) {
    F.init();
    scanf("%d%d%d", &n, &m, &k);
    F.s = n + m + 1;
    F.e = F.tot = F.s + 1;
    tot = 0;
    for (int i = 1; i <= n; ++i) cnt[i] = 0;
    for (int i = 1; i <= m; ++i) {
      scanf("%d%d", &ai[i], &bi[i]);
      av[i] = F.add_edge(ai[i], i + n, 1);
      cnt[ai[i]]++;
      bv[i] = F.add_edge(bi[i], i + n, 1);
      cnt[bi[i]]++;
      F.add_edge(i + n, F.e, 1);
    }
    val = 0;
    for (int i = 1; i <= n; ++i)
      if (k < cnt[i])
        F.add_edge(F.s, i, (cnt[i] - k) * 2), val += (cnt[i] - k) * 2;
    if (F.solve() != val) {
      for (int i = 1; i <= m; ++i) printf("%d ", 0);
    } else {
      for (int i = 1; i <= n; ++i) now[i] = 0;
      for (int i = 1; i <= m; ++i)
        if (F.ci[av[i]]) {
          if (!now[ai[i]]) {
            now[ai[i]] = ++tot;
            printf("%d ", now[ai[i]]);
          } else {
            printf("%d ", now[ai[i]]);
            now[ai[i]] = 0;
          }
        } else if (F.ci[bv[i]]) {
          if (!now[bi[i]]) {
            now[bi[i]] = ++tot;
            printf("%d ", now[bi[i]]);
          } else {
            printf("%d ", now[bi[i]]);
            now[bi[i]] = 0;
          }
        } else
          printf("%d ", ++tot);
    }
    puts("");
  }
}