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;
vector<int> g[610];
const int inf = 1e9;
struct edge {
  int from;
  int to;
  int cap;
  int flow;
  edge(int from, int to, int cap, int flow)
      : from(from), to(to), cap(cap), flow(flow) {}
  edge() {}
};
int s, t;
vector<edge> e;
vector<int> gr[2000];
void add_edge(int from, int to, int cap) {
  gr[from].push_back(e.size());
  e.push_back(edge(from, to, cap, 0));
  gr[to].push_back(e.size());
  e.push_back(edge(to, from, 0, 0));
}
int lvl[2000];
bool bfs() {
  queue<int> q;
  for (int i = s; i <= t; i++) lvl[i] = inf;
  q.push(s);
  lvl[s] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < gr[x].size(); i++) {
      int id = gr[x][i];
      if (lvl[e[id].to] > lvl[x] + 1 && e[id].cap > e[id].flow) {
        lvl[e[id].to] = lvl[x] + 1;
        q.push(e[id].to);
      }
    }
  }
  return lvl[t] < inf;
}
int pr[2000];
int dfs(int v, int flow) {
  if (!flow || v == t) return flow;
  for (; pr[v] < gr[v].size(); pr[v]++) {
    int id = gr[v][pr[v]];
    if (lvl[e[id].to] != lvl[v] + 1) continue;
    int f = dfs(e[id].to, min(flow, e[id].cap - e[id].flow));
    if (f) {
      e[id].flow += f;
      e[id ^ 1].flow -= f;
      return f;
    }
  }
  return 0;
}
int dinic() {
  int flow = 0;
  while (bfs()) {
    for (int i = s; i <= t; i++) pr[i] = 0;
    while (int f = dfs(s, inf)) {
      flow += f;
    }
  }
  return flow;
}
vector<int> ans[2000];
int res[2000];
void solve() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  s = 0;
  t = n + m + 1;
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 1; i <= n; i++) ans[i].clear();
  e.clear();
  for (int i = s; i <= t; i++) gr[i].clear();
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
    add_edge(s, i, 3);
    add_edge(i, m + x, 2);
    add_edge(i, m + y, 2);
  }
  for (int i = 1; i <= n; i++) add_edge(m + i, t, 2 * k);
  if (dinic() != 3 * m) {
    for (int i = 1; i <= m; i++) printf("0 ");
    printf("\n");
    return;
  }
  for (int i = 0; i < e.size(); i += 2) {
    if (e[i].from == s || e[i].to == t) continue;
    if (e[i].flow == 1) ans[e[i].to - m].push_back(e[i].from);
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (int)ans[i].size() - 1; j += 2)
      res[ans[i][j]] = res[ans[i][j + 1]] = cnt++;
    if (ans[i].size() % 2 == 1) res[ans[i].back()] = cnt++;
  }
  for (int i = 1; i <= m; i++) printf("%d ", res[i]);
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}