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 INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 607;
const int MAXV = 2007;
const int MAXE = 10007;
struct eT {
  void setd(int _u, int _v, int _f, int _l) {
    u = _u, v = _v, f = _f, last = _l;
  }
  int u, v, f, last;
} edge[MAXE];
int n, m, K, S = MAXV - 1, T = MAXV - 2;
vector<int> es[MAXN];
vector<int> se[MAXN];
int ke, la[MAXV];
int q[MAXV], lev[MAXV];
int c[MAXN], kc;
void init();
void input();
void work();
void addedge(int u, int v, int f);
int dinic();
bool bfs();
int dfs(int now, int lim);
int main() {
  init();
  int T;
  scanf("%d", &T);
  while (T--) {
    input();
    work();
  }
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d%d%d", &n, &m, &K);
  int u, v;
  for (int i = 1; i <= n; ++i) es[i].clear();
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    es[u].push_back(i);
    es[v].push_back(i);
  }
}
void work() {
  ke = 0;
  memset(la, -1, sizeof(la));
  for (int i = 1; i <= m; ++i) addedge(S, ((i) << 1), 1);
  int nd = 0;
  for (int i = 1; i <= n; ++i) {
    if (es[i].size() >= K) {
      addedge(((i) << 1 | 1), T, (es[i].size() - K) << 1);
      nd += (es[i].size() - K) << 1;
      for (auto x : es[i]) addedge(((x) << 1), ((i) << 1 | 1), 1);
    }
  }
  if (dinic() == nd) {
    for (int i = 1; i <= n; ++i) se[i].clear();
    memset(c, 0, sizeof(c));
    kc = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = la[((i) << 1 | 1)]; ~j; j = edge[j].last) {
        if ((edge[j].v ^ T) && edge[j].f) {
          se[i].push_back(edge[j].v >> 1);
        }
      }
    }
    for (int i = 1; i <= n; ++i) {
      int ts = se[i].size();
      for (int j = 0; j < ts; j += 2) c[se[i][j]] = c[se[i][j + 1]] = ++kc;
    }
    for (int i = 1; i <= m; ++i)
      if (!c[i]) c[i] = ++kc;
    for (int i = 1; i <= m; ++i) printf("%d ", c[i]);
    putchar('\n');
  } else {
    for (int i = 1; i <= m; ++i) printf("0 ");
    putchar('\n');
  }
}
void addedge(int u, int v, int f) {
  edge[ke].setd(u, v, f, la[u]);
  la[u] = ke++;
  edge[ke].setd(v, u, 0, la[v]);
  la[v] = ke++;
}
int dinic() {
  int ans = 0;
  while (bfs()) ans += dfs(S, INF);
  return ans;
}
bool bfs() {
  int l = 0, r = 0, now, v;
  memset(lev, -1, sizeof(lev));
  q[r++] = S;
  lev[S] = 0;
  while (l < r) {
    now = q[l++];
    for (int i = la[now]; ~i; i = edge[i].last) {
      if (edge[i].f && lev[v = edge[i].v] == -1) {
        lev[v] = lev[now] + 1;
        q[r++] = v;
      }
    }
  }
  return lev[T] != -1;
}
int dfs(int now, int lim) {
  if (now == T) return lim;
  int v, rf = lim, cf;
  for (int i = la[now]; ~i; i = edge[i].last) {
    if (edge[i].f && lev[v = edge[i].v] == lev[now] + 1) {
      cf = dfs(v, (((edge[i].f) < (rf)) ? (edge[i].f) : (rf)));
      rf -= cf;
      edge[i].f -= cf, edge[i ^ 1].f += cf;
      if (!rf) break;
    }
  }
  if (rf == lim) lev[now] = -1;
  return lim - rf;
}