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 edge {
  int des;
  int next;
  int w;
  int type;
} e[2 * 100005];
queue<int> q;
int n;
int m;
int k;
int s;
int t;
int u;
int v;
int w;
int cnt;
int head[10005];
int depth[10005];
int cur[10005];
int ans[10005];
void ins(int u, int v, int w) {
  e[++cnt].next = head[u];
  e[cnt].des = v;
  e[cnt].w = w;
  e[cnt].type = 1;
  head[u] = cnt;
  e[++cnt].next = head[v];
  e[cnt].des = u;
  e[cnt].w = 0;
  e[cnt].type = 0;
  head[v] = cnt;
}
int dfs(int u, int flow) {
  if (u == t) return flow;
  for (int i = cur[u]; i != -1; i = e[i].next) {
    cur[u] = e[i].next;
    int v = e[i].des;
    if (depth[v] == depth[u] + 1 && e[i].w > 0) {
      int di = dfs(v, min(flow, e[i].w));
      if (di > 0) {
        e[i].w -= di;
        e[i ^ 1].w += di;
        return di;
      }
    }
  }
  return 0;
}
bool bfs() {
  memset(depth, 0, sizeof(depth));
  depth[s] = 1;
  q.push(s);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = e[i].next) {
      v = e[i].des;
      if (depth[v] == 0 && e[i].w > 0) {
        depth[v] = depth[u] + 1;
        q.push(v);
      }
    }
  }
  if (depth[t]) return true;
  return false;
}
int cas;
int rd[10005];
int sum;
void init() {
  cnt = -1;
  sum = 0;
  for (int i = s; i <= t; ++i) head[i] = -1;
  for (int i = 1; i <= n; ++i) rd[i] = 0;
  for (int i = 1; i <= m; ++i) ans[i] = 0;
}
bool add_edge() {
  for (int i = 1; i <= n; ++i) {
    if (rd[i] > k) {
      if (2 * (rd[i] - k) > rd[i]) return false;
      ins(s, i, 2 * (rd[i] - k));
      sum += 2 * (rd[i] - k);
    }
  }
  return true;
}
int main() {
  scanf("%d", &cas);
  while (cas--) {
    scanf("%d %d %d", &n, &m, &k);
    s = 0;
    t = n + m + 1;
    init();
    for (int i = 1; i <= m; ++i) {
      int u;
      int v;
      scanf("%d %d", &u, &v);
      ins(u, i + n, 1);
      ins(v, i + n, 1);
      ins(i + n, t, 1);
      ++rd[u];
      ++rd[v];
    }
    if (!add_edge()) {
      for (int i = 1; i <= m; ++i) printf("0 ");
      printf("\n");
    } else {
      int maxflow = 0;
      while (bfs()) {
        for (int i = s; i <= t; i++) cur[i] = head[i];
        while (int d = dfs(s, 2000000000)) maxflow += d;
      }
      if (maxflow == sum) {
        int id = 0;
        for (int i = 1; i <= n; ++i) {
          if (rd[i] > k) {
            for (int j = head[i]; j != -1; j = e[j].next) {
              int type = e[j].type;
              if (!type) continue;
              if (e[j].w) continue;
              int des = e[j].des;
              ans[des - n] = (++id + 1) / 2;
            }
          }
        }
        id /= 2;
        for (int i = 1; i <= m; ++i)
          if (!ans[i]) ans[i] = ++id;
      }
      for (int i = 1; i <= m; ++i) printf("%d ", ans[i]);
      printf("\n");
    }
  }
  return 0;
}