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;
template <class T>
void na(vector<T>& a, int n) {
  a = vector<T>(n);
  for (T& i : a) cin >> i;
}
template <class T>
void printVector(vector<T>& a) {
  for (T& i : a) cout << i << ' ';
  cout << '\n';
}
template <class T>
vector<T> shrink(vector<T>& x) {
  vector<T> vals = x;
  sort((vals).begin(), (vals).end());
  (vals).resize(unique((vals).begin(), (vals).end()) - (vals).begin());
  for (T& i : x)
    i = upper_bound((vals).begin(), (vals).end(), i) - vals.begin();
  return vals;
}
const int MAXV = 1e5 + 15;
int layer[MAXV], last[MAXV], last_0[MAXV];
template <typename cap_type>
struct Dinic {
  static const cap_type oo = numeric_limits<cap_type>::max();
  using edge = tuple<int, int, cap_type, int>;
  int s, t, V;
  vector<edge> graph;
  Dinic(int N) : V(N) { fill(last, last + N + 1, -1); }
  void add_edge(int u, int v, cap_type cap = 1) {
    graph.emplace_back(u, v, cap, last[u]);
    last[u] = graph.size() - 1;
    graph.emplace_back(v, u, 0, last[v]);
    last[v] = graph.size() - 1;
  }
  bool bfs() {
    fill(layer, layer + V + 1, -1);
    layer[t] = 0;
    queue<int> q;
    q.push(t);
    while (!q.empty()) {
      int node = q.front();
      q.pop();
      for (int e = last[node]; e != -1; e = get<3>(graph[e])) {
        edge& din = graph[e ^ 1];
        if (get<2>(din) > 0 && layer[get<0>(din)] == -1) {
          layer[get<0>(din)] = layer[node] + 1;
          q.push(get<0>(din));
        }
      }
    }
    return layer[s] != -1;
  }
  cap_type dfs(int node, cap_type flow) {
    if (node == t) return flow;
    for (int e = last_0[node]; e != -1; e = get<3>(graph[e])) {
      edge& dout = graph[e];
      edge& din = graph[e ^ 1];
      last_0[node] = e;
      if (get<2>(dout) > 0 && layer[get<1>(dout)] + 1 == layer[get<0>(dout)]) {
        cap_type f = dfs(get<1>(dout), min(flow, get<2>(dout)));
        if (f > 0) {
          get<2>(dout) -= f;
          get<2>(din) += f;
          return f;
        }
      }
    }
    return 0;
  }
  cap_type get_mf(int src, int snk) {
    s = src, t = snk;
    cap_type totflow = 0, amt;
    while (bfs()) {
      for (int i = 0; i <= V; i++) last_0[i] = last[i];
      while ((amt = dfs(s, oo)) > 0) totflow += amt;
    }
    return totflow;
  }
};
int n, m, k;
struct Edge {
  int u, v;
  Edge() {}
  Edge(int u, int v) : u(u), v(v) {}
  int nxt(int x) { return x == u ? v : u; }
};
const int M = 777;
int asg[M];
vector<Edge> edg;
vector<vector<int>> g;
void eadd(int u, int v) {
  g[u].push_back(((int)(edg).size()));
  g[v].push_back(((int)(edg).size()));
  edg.emplace_back(u, v);
}
int deg(int u) { return ((int)(g[u]).size()); }
void clean() {
  memset(asg, 0, sizeof asg);
  edg.clear();
  g.clear();
}
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    clean();
    scanf("%d%d%d", &n, &m, &k);
    g = vector<vector<int>>(n + 1);
    for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      eadd(u, v);
    }
    bool flag = false;
    for (int i = 1; i <= n && !flag; ++i)
      if (deg(i) > 2 * k) flag = true;
    if (!flag) {
      Dinic<int> dinic(n + m + 1);
      int s = 0, t = n + m + 1;
      int TOT = 0;
      for (int i = 1; i <= n; ++i)
        TOT += max(0, 2 * (deg(i) - k)),
            dinic.add_edge(s, i, max(0, 2 * (deg(i) - k)));
      for (int i = 0; i < ((int)(edg).size()); ++i) {
        int u = edg[i].u;
        int v = edg[i].v;
        dinic.add_edge(u, i + n + 1);
        dinic.add_edge(v, i + n + 1);
        dinic.add_edge(i + n + 1, t);
      }
      int mm = dinic.get_mf(s, t);
      if (mm != TOT) {
        for (int i = 1; i <= m; ++i) printf("0%c", " \n"[i == m]);
        continue;
      }
      int cnt = 0, cur;
      for (int i = 1; i <= n; ++i) {
        cur = 0;
        for (int e = last[i]; ~e; e = get<3>(dinic.graph[e])) {
          Dinic<int>::edge& dout = dinic.graph[e];
          if (get<2>(dout) == 0 && get<1>(dout) != s) {
            if (cur == 0) ++cnt;
            asg[get<1>(dout) - (n + 1)] = cnt;
            cur ^= 1;
          }
        }
      }
      for (int i = 0; i < m; ++i) {
        if (!asg[i]) asg[i] = ++cnt;
        printf("%d%c", asg[i], " \n"[i == m - 1]);
      }
    } else
      for (int i = 1; i <= m; ++i) printf("0%c", " \n"[i == m]);
  }
  return 0;
}