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 long long inf = 1LL << 55;
using Pi = pair<long long, long long>;
using vint = vector<long long>;
struct edge {
  long long to, cap, rev;
  bool isrev;
  edge() {}
  edge(long long to, long long cap, long long rev, bool isrev)
      : to(to), cap(cap), rev(rev), isrev(isrev) {}
};
using Graph = vector<vector<edge>>;
struct Dinic {
  Graph graph;
  vint level, iter;
  Dinic(long long V) : graph(V), level(V), iter(V) {}
  void add_edge(long long from, long long to, long long cap) {
    graph[from].emplace_back(to, cap, graph[to].size(), false);
    graph[to].emplace_back(from, 0, graph[from].size() - 1, true);
  }
  bool bfs(long long s, long long t) {
    fill(level.begin(), level.end(), -1);
    queue<long long> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
      long long v = que.front();
      que.pop();
      for (long long i = 0; i < (long long)graph[v].size(); ++i) {
        edge e = graph[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
    return level[t] != -1;
  }
  long long dfs(long long v, long long t, long long f) {
    if (v == t) return f;
    for (long long& i = iter[v]; i < (long long)graph[v].size(); ++i) {
      edge& e = graph[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
        long long d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  long long max_flow(long long s, long long t) {
    long long flow = 0;
    while (bfs(s, t)) {
      fill(iter.begin(), iter.end(), 0);
      long long f;
      while ((f = dfs(s, t, inf)) > 0) flow += f;
    }
    return flow;
  }
};
signed main() {
  long long T;
  scanf("%lld", &T);
  while (T--) {
    long long n, m, k;
    scanf("%lld %lld %lld", &n, &m, &k);
    long long s = m + n, t = s + 1, V = t + 1;
    Dinic graph(V);
    vint deg(n, 0);
    for (long long i = 0; i < m; ++i) {
      long long a, b;
      scanf("%lld %lld", &a, &b);
      --a, --b;
      graph.add_edge(s, i, 1);
      graph.add_edge(i, a + m, 1);
      graph.add_edge(i, b + m, 1);
      ++deg[a];
      ++deg[b];
    }
    long long sum = 0;
    for (long long i = 0; i < n; ++i) {
      if (deg[i] <= k) continue;
      graph.add_edge(i + m, t, 2 * (deg[i] - k));
      sum += 2 * (deg[i] - k);
    }
    long long mxf = graph.max_flow(s, t);
    vint c(m, 0);
    if (sum == mxf) {
      fill(c.begin(), c.end(), -1);
      vector<vint> use(n);
      for (long long i = 0; i < m; ++i) {
        for (edge& e : graph.graph[i]) {
          if (!e.isrev && e.cap == 0) use[e.to - m].push_back(i);
        }
      }
      long long id = 1;
      for (long long i = 0; i < n; ++i) {
        for (long long j = 0; j < (long long)use[i].size(); j += 2) {
          c[use[i][j]] = c[use[i][j + 1]] = id++;
        }
      }
      for (long long i = 0; i < m; ++i) {
        if (c[i] == -1) c[i] = id++;
      }
    }
    for (long long i = 0; i < m; ++i) printf("%lld%c", c[i], " \n"[i == m - 1]);
  }
  return 0;
}