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;
inline int read() {
  int now = 0;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); now = now * 10 + c - '0', c = getchar())
    ;
  return now;
}
const double eps = 1e-9;
const int maxn = 4010;
const int maxm = 20000;
const long long INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Dinic {
  struct Edge {
    int from, to, cap, flow, nxt;
    Edge() {}
    Edge(int u, int v, int c, int f, int n)
        : from(u), to(v), cap(c), flow(f), nxt(n) {}
  } edge[maxm];
  int n, s, t, E, head[maxn];
  bool vis[maxn];
  int d[maxn], cur[maxn];
  inline void AddEdge(int f, int t, int c) {
    edge[++E] = Edge(f, t, c, 0, head[f]);
    head[f] = E;
    edge[++E] = Edge(t, f, 0, 0, head[t]);
    head[t] = E;
  }
  inline void Init(int n, int s, int t) {
    this->n = n;
    E = -1;
    this->s = s;
    head[s] = -1;
    this->t = t;
    head[t] = -1;
    for (int i = 0; i <= n; i++) head[i] = -1;
  }
  inline bool BFS() {
    memset(vis, 0, sizeof(vis));
    queue<int> Q;
    d[s] = 0;
    vis[s] = 1;
    for (Q.push(s); !Q.empty();) {
      int x = Q.front();
      Q.pop();
      for (int nxt, i = head[x]; ~i; i = nxt) {
        Edge &e = edge[i];
        nxt = e.nxt;
        if (vis[e.to] || e.cap <= e.flow) continue;
        vis[e.to] = 1;
        d[e.to] = d[x] + 1;
        Q.push(e.to);
      }
    }
    return vis[t];
  }
  inline int DFS(const int &x, int a) {
    if (x == t || a == 0) return a;
    int flow = 0, f, nxt;
    for (int &i = cur[x]; ~i; i = nxt) {
      Edge &e = edge[i];
      nxt = e.nxt;
      if (d[x] + 1 != d[e.to]) continue;
      f = DFS(e.to, min(a, e.cap - e.flow));
      if (f <= 0) continue;
      e.flow += f;
      edge[i ^ 1].flow -= f;
      flow += f;
      a -= f;
      if (!a) break;
    }
    return flow;
  }
  inline int maxFlow() { return maxFlow(s, t); }
  inline int maxFlow(int s, int t) {
    int flow = 0;
    for (; BFS();) {
      for (int i = 0; i <= n; i++) cur[i] = head[i];
      flow += DFS(s, INF);
    }
    return flow;
  }
} g;
int N, M, K;
struct Edge {
  int to, next;
} edge[maxn * 2];
int head[maxn], tot;
int ind[maxn];
int id[maxn];
void init() {
  tot = 0;
  for (int i = 1; i <= M; i++) id[i] = 0;
  for (int i = 1; i <= N; i++) ind[i] = 0, head[i] = -1;
}
void add(int u, int v) {
  edge[tot].to = v;
  edge[tot].next = head[u];
  head[u] = tot++;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d", &N, &M, &K);
    init();
    for (int i = 1; i <= M; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      ind[u]++;
      ind[v]++;
      add(u, i + N);
      add(v, i + N);
    }
    int s = N + M + 2, t = N + M + 1;
    g.Init(t + 2, s, t);
    bool flag = 1;
    int sum = 0;
    for (int i = 1; i <= N && flag; i++) {
      if (ind[i] > 2 * K) flag = 0;
      g.AddEdge(s, i, max(2 * (ind[i] - K), 0));
      sum += 2 * max((ind[i] - K), 0);
      for (int j = head[i]; ~j; j = edge[j].next) {
        int v = edge[j].to;
        g.AddEdge(i, v, 1);
      }
    }
    if (!flag) {
      for (int i = 1; i <= M; i++) {
        printf("0 ");
      }
      puts("");
      continue;
    }
    for (int i = N + 1; i <= N + M; i++) {
      g.AddEdge(i, t, 1);
    }
    if (g.maxFlow() != sum) {
      for (int i = 1; i <= M; i++) {
        printf("0 ");
      }
      puts("");
      continue;
    }
    int cnt = 1;
    for (int i = 1; i <= N; i++) {
      int num = 0;
      for (int j = g.head[i]; ~j; j = g.edge[j].nxt) {
        if (g.edge[j].flow) {
          id[g.edge[j].to - N] = cnt;
          num++;
          if (num == 2) {
            cnt++;
            num = 0;
          }
        }
      }
    }
    for (int i = 1; i <= N; i++) {
      for (int j = head[i]; ~j; j = edge[j].next) {
        int v = edge[j].to;
        v -= N;
        if (id[v]) continue;
        id[v] = cnt++;
      }
    }
    for (int i = 1; i <= M; i++) {
      printf("%d ", id[i]);
    }
    puts("");
  }
  return 0;
}