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 to;
  int cap, flow;
  size_t rev;
  int r() const { return cap - flow; }
  bool pos() const { return cap > flow; }
  Edge() : flow(0) {}
  Edge(int to, int cap, size_t rev) : to(to), cap(cap), rev(rev), flow(0) {}
};
struct MaxFlowGraph {
  int n, source, sink;
  vector<vector<Edge> > g;
  vector<int> vis;
  int hvis;
  MaxFlowGraph() {}
  MaxFlowGraph(int n, int s, int t) : n(n), source(s), sink(t), g(n), vis(n) {}
  void addEdge(int from, int to, int cap) {
    size_t p1 = g[from].size(), p2 = g[to].size();
    g[from].push_back(Edge(to, cap, p2));
    g[to].push_back(Edge(from, 0, p1));
  }
  int find() {
    hvis = 0;
    int res = 0, delta;
    do {
      hvis++;
      delta = dfs(source);
      res += delta;
    } while (delta);
    return res;
  }
  int dfs(int v, int t = (1 << 30)) {
    if (v == sink) return t;
    if (vis[v] == hvis) return 0;
    vis[v] = hvis;
    int sz = g[v].size();
    for (int i = (0); i < (sz); ++i) {
      Edge& e = g[v][i];
      if (e.pos()) {
        if (int delta = dfs(e.to, min(e.r(), t))) {
          e.flow += delta;
          g[e.to][e.rev].flow -= delta;
          return delta;
        }
      }
    }
    return 0;
  }
};
int res[1000];
int deg[1000];
void solve() {
  int n, m, k;
  scanf("%d %d", &n, &m);
  scanf("%d", &k);
  memset(deg, 0, sizeof deg);
  int OFF_E = 0;
  int OFF_V = m;
  int source = OFF_V + n;
  int sink = source + 1;
  MaxFlowGraph g(sink + 1, source, sink);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a;
    --b;
    g.addEdge(i, OFF_V + a, 1);
    g.addEdge(i, OFF_V + b, 1);
    ++deg[a];
    ++deg[b];
  }
  int expected_flow = 0;
  for (int i = (0); i < (n); ++i)
    if (deg[i] > k) {
      int cap = 2 * (deg[i] - k);
      expected_flow += cap;
      g.addEdge(OFF_V + i, sink, cap);
    }
  for (int i = (0); i < (m); ++i) g.addEdge(source, i, 1);
  int flow = g.find();
  if (flow != expected_flow) {
    for (int i = (0); i < (m); ++i) printf("0 ");
    puts("");
    return;
  }
  for (int i = (0); i < (m); ++i) res[i] = i + 1;
  vector<vector<int> > groups(n);
  for (int e = (0); e < (m); ++e)
    for (Edge& edge : g.g[e])
      if (edge.flow > 0) groups[edge.to - OFF_V].push_back(e);
  for (int i = (0); i < (n); ++i) {
    for (int p = 0; p < groups[i].size(); p += 2)
      res[groups[i][p + 1]] = res[groups[i][p]];
  }
  for (int i = (0); i < (m); ++i) printf("%d ", res[i]);
  puts("");
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) solve();
}