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 signed long long llf = (signed long long)(~0ull >> 1);
const signed int inf = (signed)(~0u >> 1);
template <typename T>
T __abs(T x) {
  return (x < 0) ? (-x) : (x);
}
template <typename T>
void pfill(T* pst, const T* ped, T val) {
  for (; pst != ped; *(pst++) = val)
    ;
}
template <typename T>
void pcopy(T* pst, const T* ped, T* pv) {
  for (; pst != ped; *(pst++) = *(pv++))
    ;
}
typedef class Edge {
 public:
  int ed, nx, cap, f;
  Edge() {}
  Edge(int ed, int nx, int cap, int f) : ed(ed), nx(nx), cap(cap), f(f) {}
} Edge;
typedef class MapManager {
 public:
  int* h;
  vector<Edge> es;
  MapManager() {}
  MapManager(int n) {
    h = new int[(n + 1)];
    pfill(h, h + n + 1, -1);
  }
  void addEdge(int u, int v, int cap, int f) {
    es.push_back(Edge(v, h[u], cap, f));
    h[u] = (signed)es.size() - 1;
  }
  void addArc(int u, int v, int cap) {
    addEdge(u, v, cap, 0);
    addEdge(v, u, cap, cap);
  }
  Edge& operator[](int p) { return es[p]; }
  void clear() {
    delete[] h;
    es.clear();
  }
} MapManager;
const int N = 605;
int n, m, K;
int s = 0, t;
int mxcap;
int deg[N];
MapManager g;
inline void init() {
  scanf("%d%d%d", &n, &m, &K);
  pfill(deg, deg + n + 1, 0);
  g = MapManager(n + m + 1);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    deg[u]++, deg[v]++;
    g.addArc(0, i, 1);
    g.addArc(i, u + m, 1);
    g.addArc(i, v + m, 1);
  }
  t = n + m + 1, mxcap = 0;
  for (int i = 1; i <= n; i++)
    if (deg[i] > K) g.addArc(i + m, t, (deg[i] - K) << 1), mxcap += deg[i] - K;
  mxcap <<= 1;
}
int cur[N << 1], _div[N << 1];
int dfs(int p, int mf) {
  if (p == t || !mf) return mf;
  int f, flow = 0;
  for (int &i = cur[p], e; ~i; i = g[i].nx) {
    e = g[i].ed;
    if (g[i].f < g[i].cap && _div[e] == _div[p] + 1 &&
        (f = dfs(e, min(mf, g[i].cap - g[i].f))) > 0) {
      g[i].f += f;
      g[i ^ 1].f -= f;
      mf -= f;
      flow += f;
      if (!mf) break;
    }
  }
  return flow;
}
queue<int> que;
bool bfs() {
  pfill(_div, _div + t + 1, -1);
  _div[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int e = que.front();
    que.pop();
    for (int i = g.h[e], eu; ~i; i = g[i].nx) {
      eu = g[i].ed;
      if (g[i].cap == g[i].f) continue;
      if (~_div[eu]) continue;
      _div[eu] = _div[e] + 1;
      que.push(eu);
    }
  }
  return _div[t] != -1;
}
int dinic() {
  int rt = 0;
  while (bfs()) {
    pcopy(cur, cur + t + 1, g.h);
    rt += dfs(s, inf);
  }
  return rt;
}
int lab[N];
vector<int> mat[N];
inline void solve() {
  int flow = dinic(), used = 0;
  if (flow != mxcap) {
    for (int i = 1; i <= m; i++) printf("0 ");
    putchar('\n');
    return;
  }
  for (int i = 1; i <= n; i++) mat[i].clear();
  for (int i = 1; i <= m; i++)
    for (int j = g.h[i]; ~j; j = g[j].nx)
      if (g[j].cap == g[j].f && g[j].ed > m) {
        mat[g[j].ed - m].push_back(i);
        break;
      }
  pfill(lab + 1, lab + m + 1, 0);
  for (int i = 1, a, b; i <= n; i++)
    while (!mat[i].empty()) {
      a = mat[i].back();
      mat[i].pop_back();
      b = mat[i].back();
      mat[i].pop_back();
      lab[a] = lab[b] = ++used;
    }
  for (int i = 1; i <= m; i++) {
    if (!lab[i]) lab[i] = ++used;
    printf("%d ", lab[i]);
  }
  putchar('\n');
}
inline void clear() { g.clear(); }
int T;
int main() {
  scanf("%d", &T);
  while (T--) {
    init();
    solve();
    clear();
  }
  return 0;
}