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;
namespace Dinic {
const int INF = 1e9 + 1e8;
const int N = 2200;
const int M = 11000;
int fst[N], nxt[M], to[M];
int cap[M];
int dis[N], q[N], ptr[N];
int V, E;
void init() {
  memset(fst, -1, sizeof fst);
  V = E = 0;
}
inline int add_node() {
  V++;
  return V - 1;
}
inline void add_edge(int u, int v, int c) {
  to[E] = v, cap[E] = c, nxt[E] = fst[u], fst[u] = E++;
  to[E] = u, cap[E] = 0, nxt[E] = fst[v], fst[v] = E++;
}
inline bool bfs(int S, int T, int n) {
  memset(dis, -1, sizeof(int) * n);
  int h = 0, t = 0;
  dis[S] = 0, q[t++] = S;
  while (h < t) {
    int u = q[h++];
    for (int e = fst[u]; ~e; e = nxt[e])
      if (cap[e] > 0 && dis[to[e]] == -1) {
        dis[to[e]] = dis[u] + 1, q[t++] = to[e];
        if (to[e] == T) return 1;
      }
  }
  return (dis[T] != -1);
}
int dfs(int u, int T, int f) {
  if (u == T) return f;
  for (int &e = ptr[u]; ~e; e = nxt[e])
    if (cap[e] > 0 && dis[to[e]] > dis[u]) {
      int ret = dfs(to[e], T, min(f, cap[e]));
      if (ret > 0) {
        cap[e] -= ret, cap[e ^ 1] += ret;
        return ret;
      }
    }
  return 0;
}
int max_flow(int S, int T, int n = V) {
  int ret = 0;
  while (bfs(S, T, n)) {
    memcpy(ptr, fst, sizeof(int) * n);
    for (int cur; (cur = dfs(S, T, INF)) > 0; ret += cur)
      ;
  }
  return ret;
}
}  // namespace Dinic
const int N = 660;
vector<int> adj[N], con[N];
int a[N], b[N], c[N];
int main() {
  ios::sync_with_stdio(0);
  int ncase;
  for (cin >> ncase; ncase--;) {
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) adj[i].clear();
    for (int i = 1; i <= m; i++) {
      cin >> a[i] >> b[i];
      c[i] = 0;
      adj[a[i]].push_back(i);
      adj[b[i]].push_back(i);
    }
    auto print = [&]() {
      for (int i = 1; i <= m; i++) cout << c[i] << ' ';
      cout << endl;
    };
    int okay = 1;
    for (int i = 1; i <= n; i++) okay &= (adj[i].size() <= 2 * k);
    if (!okay) {
      print();
      continue;
    }
    Dinic::init();
    int tot = 0;
    for (int i = 1; i <= n; i++)
      if (adj[i].size() > k) {
        Dinic::add_edge(0, i, 2 * (adj[i].size() - k));
        tot += 2 * (adj[i].size() - k);
        for (int j : adj[i]) Dinic::add_edge(i, n + j, 1);
      }
    for (int i = 1; i <= m; i++) Dinic::add_edge(n + i, n + m + 1, 1);
    if (Dinic::max_flow(0, n + m + 1, n + m + 2) != tot) {
      print();
      continue;
    }
    for (int i = 1; i <= n; i++) con[i].clear();
    for (int i = 0; i < Dinic::E; i += 2) {
      int u = Dinic::to[i ^ 1], v = Dinic::to[i], w = Dinic::cap[i ^ 1];
      if (w) {
        if (u == 0 || v == n + m + 1) continue;
        con[u].push_back(v - n);
      }
    }
    int cur = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < con[i].size(); j += 2)
        c[con[i][j]] = c[con[i][j + 1]] = ++cur;
    }
    for (int i = 1; i <= m; i++)
      if (!c[i]) c[i] = ++cur;
    print();
  }
  return 0;
}