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 n, m, k;
struct Edge {
  int a, b;
  int c;
  int next;
  Edge() {}
  Edge(int a, int b, int c, int next) : a(a), b(b), c(c), next(next) {}
};
int p[20000];
Edge e[20000];
int tot;
int h[10000], gap[10000];
int s, t;
int max_inf;
void add1(int a, int b, int c) {
  ;
  ;
  e[tot] = Edge(a, b, c, p[a]);
  p[a] = tot++;
}
void add(int a, int b, int c) {
  add1(a, b, c);
  add1(b, a, 0);
}
int dfs(int u, int inf) {
  if (u == t) return inf;
  int d = inf;
  int minh = max_inf;
  for (int i = p[u]; i != -1; i = e[i].next) {
    if (e[i].c) {
      if (h[e[i].b] + 1 == h[u]) {
        int ret = dfs(e[i].b, min(e[i].c, d));
        e[i].c -= ret;
        e[i ^ 1].c += ret;
        d -= ret;
        if (h[s] >= max_inf) return inf - d;
        if (!d) break;
      }
      minh = min(minh, h[e[i].b]);
    }
  }
  if (d == inf) {
    if (--gap[h[u]] == 0) h[s] = max_inf;
    h[u] = minh + 1;
    gap[h[u]]++;
  }
  return inf - d;
}
int maxflow() {
  int n = t + 1;
  max_inf = n;
  for (int i = 0; i < n; ++i) {
    h[i] = 0;
    gap[i] = 0;
  }
  gap[0] = n;
  int mflow = 0;
  while (h[s] < max_inf) {
    int ret = dfs(s, 1 << 30);
    mflow += ret;
  }
  return mflow;
}
int d[10000], ans[10000];
void init() {
  memset(p, -1, sizeof(p));
  tot = 0;
  memset(d, 0, sizeof(d));
  memset(ans, 0, sizeof(ans));
  s = m + n;
  t = m + n + 1;
}
int main() {
  int c;
  cin >> c;
  while (c--) {
    cin >> n >> m >> k;
    init();
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      add(i, a + m, 1);
      add(i, b + m, 1);
      add(s, i, 1);
      d[a]++;
      d[b]++;
    }
    int max_f = 0;
    int ok = 1;
    for (int i = 0; i < n; ++i) {
      if (d[i] > 2 * k) {
        max_f = -1;
        ok = 0;
        break;
      }
      if (d[i] > k) {
        add(i + m, t, 2 * (d[i] - k));
        max_f += 2 * (d[i] - k);
      }
    }
    int ret = 0;
    if (ok && max_f) {
      ret = maxflow();
      ;
      ;
    }
    if (ret == max_f) {
      memset(ans, 0, sizeof(ans));
      int ans_id = 1;
      map<int, vector<int> > ft;
      for (int i = 0; i < tot; i += 2) {
        if (e[i].c == 0) {
          ;
          ;
          int u = e[i].b - m;
          ft[u].push_back(e[i].a);
        }
      }
      for (int i = 0; i < n; ++i) {
        auto &pt = ft[i];
        for (int j = 0; j < pt.size(); j += 2) {
          ;
          ;
          ans[pt[j]] = ans_id;
          ans[pt[j + 1]] = ans_id++;
        }
        for (int j = p[i + m]; j != -1; j = e[j].next) {
          ;
          ;
          if (e[j].b == t) continue;
          if (ans[e[j].b] == 0) {
            ;
            ;
            ans[e[j].b] = ans_id++;
          }
        }
      }
    }
    for (int i = 0; i < m; ++i) {
      printf("%d ", ans[i]);
    }
    printf("\n");
  }
}