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 maxn = 2e5 + 10;
int inf = 0x3f3f3f3f;
int head[maxn];
struct node {
  int u, v, cap, nt;
  node() {}
  node(int u, int v, int cap, int nt) : u(u), v(v), cap(cap), nt(nt) {}
} edge[maxn];
int cnt;
void addedge(int u, int v, int cap) {
  edge[cnt] = node(u, v, cap, head[u]);
  head[u] = cnt++;
  edge[cnt] = node(v, u, 0, head[v]);
  head[v] = cnt++;
}
int dis[maxn];
int cur[maxn];
bool bfs(int s, int t) {
  memset(dis, -1, sizeof dis);
  queue<int> q;
  dis[s] = 0;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = edge[i].nt) {
      node no = edge[i];
      int v = no.v;
      int cap = no.cap;
      if (cap > 0 && dis[v] == -1) {
        dis[v] = dis[u] + 1;
        q.push(v);
      }
    }
  }
  return dis[t] != -1;
}
int dfs(int u, int mx, int t) {
  if (u == t) return mx;
  int used = 0;
  for (int i = cur[u]; ~i; i = edge[i].nt) {
    cur[u] = i;
    node &no = edge[i];
    int v = no.v;
    int cap = no.cap;
    if (dis[v] == dis[u] + 1 && cap > 0) {
      int w = mx - used;
      int flow = dfs(v, min(w, cap), t);
      edge[i].cap -= flow;
      edge[i ^ 1].cap += flow;
      used += flow;
      if (used == mx) return used;
    }
  }
  if (!used) dis[u] = -1;
  return used;
}
int dinic(int s, int t, int tot) {
  int ans = 0;
  while (bfs(s, t)) {
    int flow;
    for (int i = 0; i < tot; i++) cur[i] = head[i];
    while (flow = dfs(s, inf, t)) ans += flow;
  }
  return ans;
}
int deg[maxn];
int id[maxn][2];
int an[maxn], u[maxn], v[maxn];
vector<int> t[maxn];
int main() {
  int T;
  scanf("%d", &T);
  for (; T--;) {
    int n, m, k;
    scanf("%d", &n), scanf("%d", &m), scanf("%d", &k);
    for (int i = 0; i <= n + m + 2; ++i) head[i] = -1, deg[i] = 0;
    cnt = 0;
    for (int i = 1; i <= m; ++i) {
      scanf("%d", &u[i]), scanf("%d", &v[i]);
      ++deg[u[i]], ++deg[v[i]];
      addedge(0, n + i, 1);
      addedge(n + i, u[i], 1);
      id[i][0] = cnt - 1;
      addedge(n + i, v[i], 1);
      id[i][1] = cnt - 1;
    }
    int tot = 0;
    for (int i = 1; i <= n; ++i) {
      int x = deg[i] - k;
      if (x <= 0) continue;
      x *= 2;
      tot += x;
      addedge(i, n + m + 1, x);
    }
    int ans = dinic(0, n + m + 1, n + m + 2);
    if (ans == tot) {
      for (int i = 1; i <= m; i++) {
        int tt = id[i][0];
        if (edge[tt].cap == 1) {
          t[u[i]].push_back(i);
          continue;
        }
        tt = id[i][1];
        if (edge[tt].cap == 1) {
          t[v[i]].push_back(i);
          continue;
        }
        an[i] = i;
      }
      int k = m;
      for (int i = 1; i <= n; i++) {
        int sz = t[i].size();
        for (int j = 0; j < sz; j += 2) {
          ++k;
          an[t[i][j]] = k;
          an[t[i][j + 1]] = k;
        }
        t[i].clear();
      }
      for (int i = 1; i <= m; ++i) printf("%d%c", an[i], " \n"[i == m]);
    } else {
      for (int i = 1; i <= m; ++i) printf("0%c", " \n"[i == m]);
    }
  }
  return 0;
}