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 N = 1205;
const int M = 100002;
const int inf = 1000000000;
struct E {
  int to, next, cap;
} e[M * 2];
int head[N], ecnt;
int iter[N];
void adde(int fr, int to, int cap) {
  *(e + ecnt) = (E){to, *(head + fr), cap};
  *(head + fr) = ecnt++;
  *(e + ecnt) = (E){fr, *(head + to), 0};
  *(head + to) = ecnt++;
}
int dep[N];
queue<int> q;
void bfs(int s, int t) {
  memset(dep, -1, sizeof dep);
  q.push(s);
  *(dep + s) = 0;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int j = *(head + cur); j != -1; j = (e + j)->next) {
      if (*(dep + ((e + j)->to)) == -1 && (e + j)->cap > 0) {
        *(dep + (e + j)->to) = *(dep + cur) + 1;
        q.push((e + j)->to);
      }
    }
  }
}
int dfs(int o, int t, int f) {
  if (o == t || !f) return f;
  int ret = 0;
  for (int j = *(head + o); j != -1; j = (e + j)->next) {
    if ((e + j)->cap > 0 && *(dep + (e + j)->to) == *(dep + o) + 1) {
      int tmp = dfs((e + j)->to, t, min(f, (e + j)->cap));
      (e + j)->cap -= tmp;
      (e + (j ^ 1))->cap += tmp;
      ret += tmp;
      f -= tmp;
      if (!f) {
        break;
      }
    }
  }
  if (!ret) dep[o] = -1;
  return ret;
}
int dinic(int s, int t, int n) {
  int ff, ans = 0;
  for (;;) {
    bfs(s, t);
    if (*(dep + t) == -1) return ans;
    ans += dfs(s, t, inf);
  }
  return ans;
}
vector<int> G[N];
int n, m, k, ans[N], bcnt, sum;
void init() {
  sum = bcnt = ecnt = 0;
  memset(head, -1, sizeof head);
  memset(ans, 0, sizeof ans);
  for (int i = 1; i < N; i++) G[i].clear();
}
int T, nd[N], tail;
int main() {
  cin >> T;
  while (T--) {
    init();
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= m; i++) {
      int x, y;
      std::cin >> x >> y;
      G[x].push_back(i);
      G[y].push_back(i);
    }
    int S = n + m + 1, T = S + 1;
    for (int i = 1; i <= n; i++) {
      if (G[i].size() > k << 1) {
        for (int j = 1; j <= m; j++) printf("0 ");
        putchar('\n');
        goto wxh;
      }
      sum += max(((int)G[i].size() - k) << 1, 0);
      adde(S, i, max(((int)G[i].size() - k) << 1, 0));
      for (auto j : G[i]) adde(i, j + n, 1);
    }
    for (int i = 1; i <= m; i++) adde(i + n, T, 1);
    if (dinic(S, T, T) != sum) {
      for (int i = 1; i <= m; i++) printf("0 ");
      putchar('\n');
      goto wxh;
    }
    for (int i = 1; i <= n; i++) {
      tail = 0;
      for (int j = head[i]; j != -1; j = e[j].next)
        if (e[j].to != S && !e[j].cap) {
          nd[++tail] = e[j].to;
        }
      for (int j = 1; j <= tail; j += 2) {
        ans[nd[j] - n] = ans[nd[j + 1] - n] = ++bcnt;
      }
    }
    for (int i = 1; i <= m; i++)
      if (!ans[i])
        printf("%d ", ++bcnt);
      else
        printf("%d ", ans[i]);
    putchar('\n');
  wxh:;
  }
  return 0;
}