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 info {
  int to, nex, col;
} e[1010 * 2];
int T, tot, head[1010 * 3], n, m, k, d[1010 * 3], cnt;
bool b[1010 * 3];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void Link(int u, int v) {
  e[++tot].to = v;
  e[tot].nex = head[u];
  head[u] = tot;
  e[tot].col = 0;
}
namespace apple {
struct info {
  int to, nex, w, f;
} e[1010 + 1010 * 1010];
int head[1010 * 2], tot, Ans, tmp, T;
const int inf = 1e9;
void Init() {
  tot = 1;
  memset(head, 0, sizeof(head));
}
void Link(int u, int v, int f) {
  e[++tot].to = v;
  e[tot].nex = head[u];
  e[tot].f = f;
  head[u] = tot;
  e[++tot].to = u;
  e[tot].nex = head[v];
  e[tot].f = 0;
  head[v] = tot;
}
int d[1010 * 10], q[1010 * 100];
bool bfs() {
  memset(d, -1, sizeof(d));
  d[0] = 0;
  int h = 0, t = 1;
  q[1] = 0;
  for (; h != t;) {
    int u = q[++h];
    for (int i = head[u]; i; i = e[i].nex)
      if (e[i].f) {
        int v = e[i].to;
        if (d[v] == -1) d[v] = d[u] + 1, q[++t] = v;
      }
  }
  return d[T] != -1;
}
int dfs(int u, int flow) {
  if (u == T) return flow;
  int res = 0;
  bool b = 0;
  for (int i = head[u]; i; i = e[i].nex)
    if (e[i].f) {
      int v = e[i].to;
      if (d[v] != d[u] + 1) continue;
      int tmp = dfs(v, min(e[i].f, flow));
      if (tmp) {
        e[i].f -= tmp;
        flow -= tmp;
        e[i ^ 1].f += tmp;
        res += tmp;
        b = 1;
        if (!flow) break;
      }
    }
  if (!b) d[u] = -1;
  return res;
}
int ans[1010 * 10];
void solve() {
  T = n + m + 1;
  Ans = 0, tmp = 0;
  while (bfs())
    while (tmp = dfs(0, inf)) Ans += tmp;
  if (Ans != (::cnt)) {
    for (int i = 1; i <= m; ++i) printf("0 ");
  } else {
    memset(ans, 0, sizeof(ans));
    int col = 100500, p = 1, c = 0;
    for (int u = 1; u <= n; ++u) {
      bool flag = 0;
      for (int i = head[u]; i; i = e[i].nex)
        if (!e[i].f && e[i].to > n) {
          ans[e[i].to - n] = p;
          if ((++c) == 2) ++p, c = 0;
          flag = 1;
        }
    }
    for (int i = 1; i <= m; ++i) printf("%d ", (ans[i] == 0) ? col-- : ans[i]);
  }
  puts("");
}
};  // namespace apple
int main() {
  for (T = read(); T--;) {
    n = read(), m = read(), k = read();
    tot = 1, memset(head, 0, sizeof(head));
    memset(d, 0, sizeof(d)), memset(b, 0, sizeof(b));
    cnt = 0;
    apple::Init();
    for (int i = 1; i <= m; ++i) {
      apple::Link(n + i, n + m + 1, 1);
      int u = read(), v = read();
      Link(u, v), Link(v, u);
      ++d[u], ++d[v];
    }
    bool flag = 0;
    for (int i = 1; i <= n; ++i) {
      if (d[i] > 2 * k) {
        for (int o = 1; o <= m; ++o) printf("%d ");
        puts("");
        flag = 1;
        break;
      }
      if (d[i] <= k) continue;
      cnt += 2 * (d[i] - k), b[i] = 1;
      apple::Link(0, i, 2 * (d[i] - k));
      for (int o = head[i]; o; o = e[o].nex) {
        int t = o >> 1;
        apple::Link(i, n + t, 1);
      }
    }
    if (!flag) apple::solve();
  }
  return 0;
}