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 std::lower_bound;
using std::max;
using std::min;
using std::random_shuffle;
using std::reverse;
using std::sort;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
void open(const char *s) {}
void open2(const char *s) {}
int rd() {
  int s = 0, c, b = 0;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-') {
    c = getchar();
    b = 1;
  }
  do {
    s = s * 10 + c - '0';
  } while ((c = getchar()) >= '0' && c <= '9');
  return b ? -s : s;
}
void put(int x) {
  if (!x) {
    putchar('0');
    return;
  }
  static int c[20];
  int t = 0;
  while (x) {
    c[++t] = x % 10;
    x /= 10;
  }
  while (t) putchar(c[t--] + '0');
}
int upmin(int &a, int b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int upmax(int &a, int b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
const int M = 20000;
const int N = 2000;
namespace flow {
int v[M], c[M], h[N], t[M];
int cnt;
void add(int x, int y, int z) {
  cnt++;
  v[cnt] = y;
  c[cnt] = z;
  t[cnt] = h[x];
  h[x] = cnt;
}
int op(int x) { return ((x - 1) ^ 1) + 1; }
int S, T;
int d[N];
queue<int> q;
int bfs() {
  memset(d, 0, sizeof d);
  d[S] = 1;
  q.push(S);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = h[x]; i; i = t[i])
      if (c[i] && !d[v[i]]) {
        d[v[i]] = d[x] + 1;
        q.push(v[i]);
      }
  }
  return d[T];
}
int dfs(int x, int flow) {
  if (x == T) return flow;
  int res = 0;
  for (int i = h[x]; i; i = t[i])
    if (c[i] && d[v[i]] == d[x] + 1) {
      int u = dfs(v[i], min(flow, c[i]));
      c[i] -= u;
      c[op(i)] += u;
      res += u;
      flow -= u;
      if (!flow) break;
    }
  return res;
}
int solve() {
  int ans = 0;
  while (bfs()) ans += dfs(S, 0x7fffffff);
  return ans;
}
}  // namespace flow
using flow::S;
using flow::T;
void add(int x, int y, int z) {
  flow::add(x, y, z);
  flow::add(y, x, 0);
}
int n, m, k;
vector<int> e[N];
int deg[N];
int lx[N], ly[N];
int s[N];
void solve() {
  memset(deg, 0, sizeof deg);
  memset(flow::h, 0, sizeof flow::h);
  memset(s, 0, sizeof s);
  flow::cnt = 0;
  scanf("%d%d%d", &n, &m, &k);
  S = n + m + 1;
  T = n + m + 2;
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    lx[i] = x;
    ly[i] = y;
    deg[x]++;
    deg[y]++;
    add(S, i, 1);
    add(i, m + x, 1);
    add(i, m + y, 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (deg[i] > k) {
      add(i + m, T, 2 * (deg[i] - k));
      ans += 2 * (deg[i] - k);
    }
  ans -= flow::solve();
  if (ans) {
    for (int i = 1; i <= m; i++) printf("%d ", 0);
    printf("\n");
    return;
  }
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 1; i <= m; i++)
    for (int j = flow::h[i]; j; j = flow::t[j])
      if (flow::v[j] == lx[i] + m && !flow::c[j])
        e[lx[i]].push_back(i);
      else if (flow::v[j] == ly[i] + m && !flow::c[j])
        e[ly[i]].push_back(i);
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < (int)e[i].size(); j += 2) {
      cnt++;
      s[e[i][j]] = cnt;
      s[e[i][j + 1]] = cnt;
    }
  for (int i = 1; i <= m; i++) {
    if (!s[i]) s[i] = ++cnt;
    printf("%d ", s[i]);
  }
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}