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 std::vector;
struct Edge {
  int u, v;
  int c;
  int rev;
  Edge(int u, int v, int c, int rev) : u(u), v(v), c(c), rev(rev) {}
};
vector<Edge> g[1205];
int in[1205];
int queue[1205];
int depth[1205];
int color[1205];
vector<int> help[1205];
void addEdge(int u, int v, int c) {
  int ur = g[u].size(), vr = g[v].size();
  g[u].push_back(Edge(u, v, c, vr));
  g[v].push_back(Edge(v, u, 0, ur));
}
int bfs(int s, int t) {
  for (int i = s; i <= t; i++) depth[i] = 0;
  int he = 1, ta = 0;
  depth[s] = 1, queue[++ta] = s;
  while (he <= ta) {
    int u = queue[he++];
    for (Edge e : g[u]) {
      if (e.c != 0 && depth[e.v] == 0) {
        depth[e.v] = depth[u] + 1;
        queue[++ta] = e.v;
      }
    }
  }
  return depth[t] != 0;
}
int min(int a, int b) { return a > b ? b : a; }
int dfs(int s, int t, int upper) {
  if (upper == 0 || s == t)
    return upper;
  else {
    int sumFlow = 0;
    for (Edge& e : g[s]) {
      if (upper == 0) break;
      if (e.c != 0 && depth[e.v] == depth[s] + 1) {
        int add = dfs(e.v, t, min(e.c, upper));
        if (add != 0) depth[e.v] = 0;
        Edge& revE = g[e.v][e.rev];
        sumFlow += add;
        revE.c += add;
        upper -= add;
        e.c -= add;
      }
    }
    return sumFlow;
  }
}
int dinic(int s, int t) {
  int inf = 1e8 + 7;
  int res = 0;
  while (bfs(s, t) != 0) {
    int add = -1;
    while (add != 0) {
      add = dfs(s, t, inf);
      res += add;
    }
  }
  return res;
}
void fullFill(int n, int m) {
  int total = 0;
  for (int i = 1; i <= m; i++) {
    int u = n + i, find = 0;
    for (Edge e : g[u]) {
      if (e.c == 0 && e.v >= 1 && e.v <= n) {
        help[e.v].push_back(i);
        find = e.v;
        break;
      }
    }
    if (!find) color[i] = ++total;
  }
  for (int i = 1; i <= n; i++) {
    if (help[i].size() != 0) {
      int bit = 0;
      for (int e : help[i]) {
        bit = !bit;
        if (bit) total++;
        color[e] = total;
      }
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int s = 0, t = n + m + 1;
    for (int i = s; i <= t; i++)
      in[i] = color[i] = 0, g[i].clear(), help[i].clear();
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      in[u]++, in[v]++;
      int cur = n + i;
      addEdge(s, cur, 1);
      addEdge(cur, u, 1);
      addEdge(cur, v, 1);
    }
    int sumFlow = 0;
    for (int i = 1; i <= n; i++) {
      if (in[i] > k) {
        int need = 2 * (in[i] - k);
        addEdge(i, t, need);
        sumFlow += need;
      }
    }
    int resFlow = dinic(s, t);
    if (resFlow == sumFlow) fullFill(n, m);
    for (int i = 1; i <= m; i++) printf("%d ", color[i]);
    printf("\n");
  }
  return 0;
}