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;
vector<pair<int, int> > a[605];
int n, m, l = 1, K, Ans = 0, sum = 0;
int to[4405 << 1], h[4405 << 1], s[4405], w[4405 << 1], in[4405], now[4405],
    d[4405], ans[4405];
queue<int> Q;
void hah(int x, int y, int z) {
  to[++l] = y, h[l] = s[x], s[x] = l, w[l] = z;
  to[++l] = x, h[l] = s[y], s[y] = l, w[l] = 0;
}
bool bfs() {
  for (int i = 0; i <= n + m + 1; i++) in[i] = 0;
  while (!Q.empty()) Q.pop();
  Q.push(0);
  in[0] = 1;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = s[x]; i; i = h[i]) {
      if (w[i] && !in[to[i]]) {
        in[to[i]] = in[x] + 1;
        if (to[i] == n + m + 1) return true;
        Q.push(to[i]);
      }
    }
  }
  return false;
}
int dfs(int x, int flow) {
  int use = 0;
  if (x == n + m + 1) return flow;
  for (int i = now[x]; i; i = h[i]) {
    if (in[to[i]] == in[x] + 1 && w[i]) {
      int d = dfs(to[i], min(w[i], flow - use));
      w[i] -= d, w[i ^ 1] += d;
      use += d;
      now[x] = i;
      if (use == flow) return use;
    }
  }
  if (!use) in[x] = -1;
  return use;
}
void dinic() {
  while (bfs()) {
    for (int i = 0; i <= n + m + 1; i++) now[i] = s[i];
    Ans += dfs(0, 1000000007);
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    l = 1;
    Ans = sum = 0;
    scanf("%d%d%d", &n, &m, &K);
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      d[x]++, d[y]++;
      hah(n + i, n + m + 1, 1);
      hah(x, n + i, 1);
      a[x].push_back({l - 1, i});
      hah(y, n + i, 1);
      a[y].push_back({l - 1, i});
    }
    for (int i = 1; i <= n; i++) {
      if (d[i] > K) {
        hah(0, i, (d[i] - K) * 2);
        sum += (d[i] - K) * 2;
      }
    }
    dinic();
    if (sum != Ans) {
      for (int i = 1; i < m; i++) {
        printf("0 ");
      }
      printf("0\n");
      for (int i = 0; i <= n + m + 1; i++) d[i] = s[i] = 0;
      for (int i = 1; i <= n; i++) a[i].clear();
      continue;
    }
    int cnt = 0, op = 0;
    for (int i = 1; i <= n; i++) {
      int p = a[i].size();
      for (int j = 0; j < p; j++) {
        if (!w[a[i][j].first]) {
          op++;
          if (op % 2) ++cnt;
          ans[a[i][j].second] = cnt;
        }
      }
    }
    for (int i = 1; i <= m; i++) {
      if (!ans[i]) ans[i] = ++cnt;
    }
    for (int i = 1; i < m; i++) {
      printf("%d ", ans[i]);
      ans[i] = 0;
    }
    printf("%d\n", ans[m]);
    ans[m] = 0;
    for (int i = 0; i <= n + m + 1; i++) d[i] = s[i] = 0;
    for (int i = 1; i <= n; i++) a[i].clear();
  }
  return 0;
}