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 MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() { return abs((int)mt()); }
const int foo = (int)1e9;
namespace Maxflow {
const int maxv = 1e5 + 5;
const int maxe = 1e6 + 5;
int n, s, t, E;
int adj[maxe], nxt[maxe], lst[maxv], ptr[maxv], lev[maxv], que[maxv];
int flw[maxe], cap[maxe];
void init(int nn, int ss, int tt) {
  n = nn, s = ss, t = tt, E = 0;
  fill_n(lst, n, -1);
}
int add(int u, int v, int c1, int c2) {
  adj[E] = v, flw[E] = 0, cap[E] = c1, nxt[E] = lst[u], lst[u] = E++;
  adj[E] = u, flw[E] = 0, cap[E] = c2, nxt[E] = lst[v], lst[v] = E++;
  return E - 2;
}
int bfs() {
  fill_n(lev, n, 0), lev[s] = 1;
  int qsize = 0;
  que[qsize++] = s;
  for (int i = 0; i < qsize; i++) {
    for (int u = que[i], e = lst[u]; ~e; e = nxt[e]) {
      int v = adj[e];
      if (flw[e] < cap[e] && !lev[v]) {
        lev[v] = lev[u] + 1;
        que[qsize++] = v;
      }
    }
  }
  return lev[t];
}
int dfs(int u, int bot) {
  if (u == t) return bot;
  for (int& e = ptr[u]; ~e; e = nxt[e]) {
    int v = adj[e];
    int delta = 0;
    if (lev[v] == lev[u] + 1 && flw[e] < cap[e] &&
        (delta = dfs(v, min(bot, cap[e] - flw[e]))) > 0) {
      flw[e] += delta;
      flw[e ^ 1] -= delta;
      return delta;
    }
  }
  return 0;
}
int maxflow(int ss = -1, int tt = -1) {
  if (~ss) s = ss;
  if (~tt) t = tt;
  fill_n(flw, E, 0);
  int total = 0;
  while (bfs()) {
    for (int i = 0; i < n; i++) ptr[i] = lst[i];
    for (int delta = dfs(s, foo); delta > 0; delta = dfs(s, foo))
      total += delta;
  }
  return total;
}
vector<pair<pair<int, int>, int> > gomory_hu() {
  vector<pair<pair<int, int>, int> > tree;
  vector<int> p(n);
  for (int u = 1; u < n; u++) {
    tree.push_back(make_pair(make_pair(p[u], u), maxflow(u, p[u])));
    for (int v = u + 1; v < n; ++v) {
      if (lev[v] && p[v] == p[u]) {
        p[v] = u;
      }
    }
  }
  return tree;
}
}  // namespace Maxflow
const int maxn = 600 + 5;
int n, m, k;
vector<pair<int, int> > edges;
int deg[maxn];
void chemthan() {
  int test;
  cin >> test;
  while (test--) {
    cin >> n >> m >> k;
    edges.resize(m);
    fill_n(deg, n, 0);
    for (pair<int, int>& e : edges)
      cin >> e.first >> e.second, e.first--, e.second--, deg[e.first]++,
          deg[e.second]++;
    int tot = m + n, s = tot++, t = tot++;
    Maxflow::init(tot, s, t);
    static int id[maxn][2];
    for (int i = (0); i < (m); ++i) {
      Maxflow::add(s, i, 1, 0);
      id[i][0] = Maxflow::add(i, m + edges[i].first, 1, 0);
      id[i][1] = Maxflow::add(i, m + edges[i].second, 1, 0);
    }
    int sum = 0;
    for (int u = (0); u < (n); ++u)
      if (deg[u] > k) {
        Maxflow::add(m + u, t, (deg[u] - k) * 2, 0);
        sum += (deg[u] - k) * 2;
      }
    if (Maxflow::maxflow() != sum) {
      for (int i = (0); i < (m); ++i) cout << 0 << " \n"[i == m - 1];
      continue;
    }
    static vector<int> g[maxn];
    for (int i = (0); i < (n); ++i) g[i].clear();
    for (int i = (0); i < (m); ++i) {
      if (Maxflow::flw[id[i][0]]) {
        int x = edges[i].first;
        g[x].push_back(i);
      } else if (Maxflow::flw[id[i][1]]) {
        int x = edges[i].second;
        g[x].push_back(i);
      }
    }
    static int res[maxn];
    fill_n(res, m, -1);
    int ptr = 0;
    for (int i = (0); i < (n); ++i) {
      for (int ix : g[i]) {
        res[ix] = ptr / 2;
        ptr++;
      }
    }
    ptr >>= 1;
    for (int i = (0); i < (m); ++i)
      if (res[i] == -1) res[i] = ptr++;
    for (int i = (0); i < (m); ++i) cout << res[i] + 1 << " \n"[i == m - 1];
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}