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 = 3000 + 10;
const int maxm = 1e6 + 10;
const long long INF = 1e16;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxblock = sqrt(maxn) + 10;
int n, m, k;
int s, t;
struct Edge {
  int from, to, next;
  int cap, flow;
  void get(int u, int a, int b, int c, int d) {
    from = u;
    to = a;
    next = b;
    cap = c;
    flow = d;
  }
} edge[maxm];
int tol;
int head[maxn];
int gap[maxn], dep[maxn], pre[maxn], cur[maxn];
void init() {
  tol = 0;
  memset(head, -1, sizeof head);
}
void add_edge(int u, int v, int w, int rw = 0) {
  edge[tol].get(u, v, head[u], w, 0);
  head[u] = tol++;
  edge[tol].get(v, u, head[v], rw, 0);
  head[v] = tol++;
}
int sap(int start, int end, int N) {
  memset(gap, 0, sizeof gap);
  memset(dep, 0, sizeof dep);
  memcpy(cur, head, sizeof head);
  int u = start;
  pre[u] = -1;
  gap[0] = N;
  int ans = 0;
  while (dep[start] < N) {
    if (u == end) {
      int Min = INF;
      for (int i = pre[u]; i != -1; i = pre[edge[i ^ 1].to])
        if (Min > edge[i].cap - edge[i].flow) Min = edge[i].cap - edge[i].flow;
      for (int i = pre[u]; i != -1; i = pre[edge[i ^ 1].to]) {
        edge[i].flow += Min;
        edge[i ^ 1].flow -= Min;
      }
      u = start;
      ans += Min;
      continue;
    }
    bool flag = false;
    int v;
    for (int i = cur[u]; i != -1; i = edge[i].next) {
      v = edge[i].to;
      if (edge[i].cap - edge[i].flow && dep[v] + 1 == dep[u]) {
        flag = true;
        cur[u] = pre[v] = i;
        break;
      }
    }
    if (flag) {
      u = v;
      continue;
    }
    int Min = N;
    for (int i = head[u]; i != -1; i = edge[i].next)
      if (edge[i].cap - edge[i].flow && dep[edge[i].to] < Min) {
        Min = dep[edge[i].to];
        cur[u] = i;
      }
    gap[dep[u]]--;
    if (!gap[dep[u]]) return ans;
    dep[u] = Min + 1;
    gap[dep[u]]++;
    if (u != start) u = edge[pre[u] ^ 1].to;
  }
  return ans;
}
int cnt = 0;
int res[maxn];
int in[maxn];
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    init();
    memset(in, 0, sizeof(in));
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      add_edge(u, n + i, 1);
      add_edge(v, n + i, 1);
      in[u]++;
      in[v]++;
    }
    s = 0, t = n + m + 1;
    for (int i = 1; i <= m; i++) {
      add_edge(n + i, t, 1);
    }
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      if (in[i] > 2 * k) {
        flag = 1;
        break;
      }
      if (in[i] > k && in[i] <= 2 * k) {
        add_edge(s, i, 2 * (in[i] - k));
      }
    }
    if (flag) {
      for (int i = 1; i <= m; i++) printf("0 ");
      printf("\n");
      continue;
    }
    sap(s, t, n + m + 2);
    for (int i = 0; i < tol; i++) {
      if (edge[i].from == 0) {
        int v = edge[i].to;
        if (edge[i].flow != 2 * (in[v] - k)) {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      for (int i = 1; i <= m; i++) {
        printf("0 ");
      }
      printf("\n");
      continue;
    }
    vector<int> ans;
    for (int u = 1; u <= n; u++) {
      for (int i = head[u]; ~i; i = edge[i].next) {
        int v = edge[i].to;
        if (v <= n) continue;
        if (edge[i].cap == 0) continue;
        if (edge[i].cap == edge[i].flow) {
          ans.push_back(v - n);
        }
      }
    }
    cnt = 0;
    for (int i = 1; i <= m; i++) res[i] = 0;
    for (int i = 0; i < ans.size(); i += 2) {
      ++cnt;
      res[ans[i]] = res[ans[i + 1]] = cnt;
    }
    for (int i = 1; i <= m; i++) {
      if (!res[i]) res[i] = ++cnt;
    }
    for (int i = 1; i <= m; i++) printf("%d ", res[i]);
    printf("\n");
  }
  return 0;
}