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;
using LL = long long;
using ULL = unsigned long long;
void err() { cout << endl; }
template <template <typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) {
  for (auto x : a) cout << x << ' ';
  err(args...);
}
template <typename T, typename... Args>
void err(T a, Args... args) {
  cout << a << ' ';
  err(args...);
}
const int N = 2000, INF = 1E9;
int n, K;
vector<int> G[N], Gid[N];
struct E {
  int to, cp;
  E(int to, int cp) : to(to), cp(cp) {}
};
struct Dinic {
  static const int M = 1E5 * 5;
  int n, m, s, t;
  vector<E> edges;
  vector<int> G[M];
  int d[M], cur[M];
  void init(int n, int s, int t) {
    this->n = n;
    this->s = s;
    this->t = t;
    for (decay<decltype(n + 1)>::type i = (0), _i = (n + 1); i < _i; ++i)
      G[i].clear();
    edges.clear();
    m = 0;
  }
  void addedge(int u, int v, int cap) {
    edges.emplace_back(v, cap);
    edges.emplace_back(u, 0);
    G[u].push_back(m++);
    G[v].push_back(m++);
  }
  bool BFS() {
    fill(d, d + n + m + 10, 0);
    queue<int> Q;
    Q.push(s);
    d[s] = 1;
    while (!Q.empty()) {
      int x = Q.front();
      Q.pop();
      for (int& i : G[x]) {
        E& e = edges[i];
        if (!d[e.to] && e.cp > 0) {
          d[e.to] = d[x] + 1;
          Q.push(e.to);
        }
      }
    }
    return d[t];
  }
  int DFS(int u, int cp) {
    if (u == t || !cp) return cp;
    int tmp = cp, f;
    for (int& i = cur[u]; i < G[u].size(); ++i) {
      E& e = edges[G[u][i]];
      if (d[u] + 1 == d[e.to]) {
        f = DFS(e.to, min(cp, e.cp));
        e.cp -= f;
        edges[G[u][i] ^ 1].cp += f;
        cp -= f;
        if (!cp) break;
      }
    }
    return tmp - cp;
  }
  int go() {
    int flow = 0;
    while (BFS()) {
      fill(cur, cur + n + m + 10, 0);
      flow += DFS(s, INF);
    }
    return flow;
  }
} DC;
int st[N], ed[N], cc[N];
int solve(int m) {
  for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i)
    if ((int)G[i].size() > 2 * K) return 0;
  int S = 0, T = n + m + 1;
  DC.init(n + m + 10, S, T);
  int maxf = 0;
  for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) {
    int d = G[i].size();
    if (d > K) {
      DC.addedge(S, i, 2 * (d - K));
      maxf += 2 * (d - K);
    }
  }
  for (decay<decltype(m + 1)>::type i = (1), _i = (m + 1); i < _i; ++i) {
    DC.addedge(n + i, T, 1);
    DC.addedge(st[i], n + i, 1);
    DC.addedge(ed[i], n + i, 1);
  }
  int color = 0;
  if (DC.go() == maxf) {
    fill(cc, cc + m + 1, 0);
    int flag = 0;
    for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) {
      for (int& x : DC.G[i]) {
        if (DC.edges[x].cp == 0) {
          int t = DC.edges[x].to - n;
          if (t < 1 || t > m) continue;
          if (flag)
            cc[t] = color;
          else
            cc[t] = ++color;
          ;
          flag ^= 1;
        }
      }
      assert(flag == 0);
    }
    for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) {
      for (int& id : Gid[i]) {
        if (cc[id]) continue;
        cc[id] = ++color;
        ;
      }
    }
    map<int, int> mm;
    for (decay<decltype(m + 1)>::type i = (1), _i = (m + 1); i < _i; ++i)
      mm[cc[i]]++;
    for (auto& s : mm) assert(s.second <= 2);
    set<int> ss;
    for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) {
      ss.clear();
      for (int& j : Gid[i]) ss.insert(cc[j]);
      assert((int)ss.size() <= K);
    }
    for (decay<decltype(m + 1)>::type i = (1), _i = (m + 1); i < _i; ++i)
      printf("%d%c", cc[i], i == _i - 1 ? '\n' : ' ');
    return 1;
  }
  return 0;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int m;
    cin >> n >> m >> K;
    for (decay<decltype(n + 1)>::type i = (1), _i = (n + 1); i < _i; ++i) {
      G[i].clear();
      Gid[i].clear();
    }
    for (decay<decltype(m + 1)>::type i = (1), _i = (m + 1); i < _i; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
      Gid[u].push_back(i);
      Gid[v].push_back(i);
      st[i] = u;
      ed[i] = v;
    }
    if (!solve(m)) {
      for (decay<decltype(m)>::type i = (0), _i = (m); i < _i; ++i)
        printf("0%c", i == _i - 1 ? '\n' : ' ');
    }
  }
}