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 INF = 0x3f3f3f3f;
const int N = 9999;
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) {}
  } edges[N];
  int n, s, t, E, head[N];
  bool vis[N];
  int d[N], cur[N];
  vector<int> vec[N];
  int ans[N];
  inline void AddEdge(int f, int t, int c) {
    edges[++E] = Edge(f, t, c, 0, head[f]);
    head[f] = E;
    edges[++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++) vec[i].clear();
    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 != -1; i = nxt) {
        Edge& e = edges[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 != -1; i = nxt) {
      Edge& e = edges[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;
      edges[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;
  }
  inline void solve(int n, int m) {
    for (int x = 1; x <= m; x++)
      for (int nxt, i = head[x]; i != -1; i = nxt) {
        Edge& e = edges[i];
        nxt = e.nxt;
        if (e.flow == 1) vec[e.to - m].push_back(x);
      }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      cnt++;
      for (int j = 0; j < vec[i].size(); j++) {
        if (j % 2 == 0)
          ans[vec[i][j]] = cnt;
        else
          ans[vec[i][j]] = cnt++;
      }
    }
    for (int i = 1; i <= m; i++) printf("%d%c", ans[i], i == m ? '\n' : ' ');
  }
} g;
int main() {
  int cas, n, m, k, x, y;
  scanf("%d", &cas);
  while (cas--) {
    scanf("%d%d%d", &n, &m, &k);
    int s = 0, t = n + m + 1;
    g.Init(t + 1, s, t);
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &x, &y);
      g.AddEdge(i, x + m, 2);
      g.AddEdge(i, y + m, 2);
      g.AddEdge(s, i, 3);
    }
    for (int i = 1; i <= n; i++) g.AddEdge(i + m, t, 2 * k);
    int ma = g.maxFlow();
    if (ma != 3 * m) {
      for (int i = 1; i <= m; i++) printf("0%c", i == m ? '\n' : ' ');
      continue;
    }
    g.solve(n, m);
  }
}