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 namespace chrono;
const int N = 1205;
const int INF = 0x3f3f3f3f;
template <class T>
bool read(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-' && c != EOF)
    ;
  if (c == EOF) return false;
  T flag = 1;
  if (c == '-') {
    flag = -1;
    x = 0;
  } else
    x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  x *= flag;
  return true;
}
template <class T, class... R>
bool read(T& a, R&... b) {
  if (!read(a)) return false;
  return read(b...);
}
mt19937 gen(steady_clock::now().time_since_epoch().count());
struct edge {
  int to, cap, next;
} e[N * 4];
int head[N], cnt, depth[N], group[N];
void add(int u, int v, int c) {
  e[cnt] = {v, c, head[u]};
  head[u] = cnt++;
}
void add_edge(int u, int v, int c) {
  add(u, v, c);
  add(v, u, 0);
}
bool isap_bfs(int s, int t) {
  memset(depth, -1, sizeof(depth));
  memset(group, 0, sizeof(group));
  group[depth[t] = 0]++;
  queue<int> q;
  q.push(t);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = e[i].next) {
      int v = e[i].to;
      if (~depth[v]) continue;
      group[depth[v] = depth[u] + 1]++;
      q.push(v);
    }
  }
  return ~depth[s];
}
int isap_dfs(int u, int t, int c) {
  if (u == t) return c;
  int tmp = c;
  for (int i = head[u]; tmp && ~i; i = e[i].next) {
    int v = e[i].to;
    if (depth[v] + 1 == depth[u] && e[i].cap) {
      int d = isap_dfs(v, t, min(tmp, e[i].cap));
      e[i].cap -= d;
      e[i ^ 1].cap += d;
      tmp -= d;
    }
  }
  if (tmp) {
    if (!--group[depth[u]]) depth[t] = -1;
    group[++depth[u]]++;
  }
  return c - tmp;
}
int isap(int s, int t) {
  if (!isap_bfs(s, t)) return 0;
  int max_flow = 0;
  while (~depth[t]) max_flow += isap_dfs(s, t, INF);
  return max_flow;
}
int deg[N], x[N], y[N], xe[N], ye[N];
vector<int> edg[N];
int main() {
  time_point<steady_clock> start = steady_clock::now();
  int T, n, m, k;
  read(T);
  while (T--) {
    read(n, m, k);
    int s = 0, t = n + m + 1;
    cnt = 0;
    for (int i = s; i <= t; i++) {
      head[i] = -1;
      deg[i] = 0;
      edg[i].clear();
    }
    for (int i = 1; i <= m; i++) {
      read(x[i], y[i]);
      deg[x[i]]++;
      deg[y[i]]++;
      edg[x[i]].push_back(i);
      edg[y[i]].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      if (deg[i] > 2 * k) {
        k = -1;
        break;
      }
    }
    if (k == -1) {
      for (int i = 1; i <= m; i++) printf("0 ");
      puts("");
      continue;
    }
    int tot = 0;
    for (int i = 1; i <= n; i++) {
      if (deg[i] > k) {
        tot += deg[i] - k;
        add_edge(m + i, t, 2 * (deg[i] - k));
      }
    }
    tot *= 2;
    for (int i = 1; i <= m; i++) {
      add_edge(s, i, 1);
      add_edge(i, m + x[i], 1);
      xe[i] = cnt - 1;
      add_edge(i, m + y[i], 1);
      ye[i] = cnt - 1;
    }
    if (isap(s, t) == tot) {
      for (int i = 1; i <= m; i++) deg[i] = 0;
      k = 1;
      for (int i = 1; i <= n; i++) {
        int c = 0;
        for (auto j : edg[i]) {
          if (x[j] == i && e[xe[j]].cap || y[j] == i && e[ye[j]].cap) {
            if (c == 0)
              deg[j] = k;
            else
              deg[j] = k++;
            c ^= 1;
          }
        }
      }
      for (int i = 1; i <= m; i++)
        if (!deg[i]) deg[i] = k++;
      for (int i = 1; i <= m; i++) printf("%d ", deg[i]);
      puts("");
    } else {
      for (int i = 1; i <= m; i++) printf("0 ");
      puts("");
    }
  }
  cerr << endl
       << "------------------------------" << endl
       << "Time: "
       << duration<double, milli>(steady_clock::now() - start).count() << " ms."
       << endl;
  return 0;
}