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_of_int = 1e9;
const long long INF_of_ll = 1e18;
template <typename T>
void Read(T &x) {
  bool w = 1;
  x = 0;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') w = 0, c = getchar();
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  if (!w) x = -x;
}
template <typename T>
void Write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) Write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 1e5 + 10;
struct Edge {
  int u, v, cap, flow;
};
vector<Edge> E;
vector<int> G[N];
int S, T;
int d[N], vis[N];
void init(int n) {
  E.clear();
  for (int i = 0; i <= n; ++i) G[i].clear();
}
void add(int u, int v, int cap) {
  E.push_back((Edge){u, v, cap, 0});
  E.push_back((Edge){v, u, 0, 0});
  int m = E.size();
  G[u].push_back(m - 2);
  G[v].push_back(m - 1);
}
bool bfs() {
  memset(vis, 0, sizeof(vis));
  memset(d, 0, sizeof(d));
  queue<int> q;
  q.push(S);
  vis[S] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < (signed)G[u].size(); ++i) {
      Edge e = E[G[u][i]];
      if (!vis[e.v] && e.cap > e.flow) {
        vis[e.v] = 1;
        d[e.v] = d[u] + 1;
        q.push(e.v);
      }
    }
  }
  return vis[T];
}
int dfs(int u, int a) {
  if (u == T || !a) return a;
  int flow = 0;
  for (int i = 0; i < (signed)G[u].size(); ++i) {
    Edge &e = E[G[u][i]];
    if (d[e.v] != d[u] + 1) continue;
    int f = dfs(e.v, min(a, e.cap - e.flow));
    flow += f;
    a -= f;
    e.flow += f;
    E[G[u][i] ^ 1].flow -= f;
    if (!a) break;
  }
  if (!flow) d[u] = 0;
  return flow;
}
int Max_flow() {
  int flow = 0;
  while (bfs()) flow += dfs(S, INF_of_int);
  return flow;
}
int du[N], u[N], v[N], f[N], pre[N], bel[N];
vector<int> pool[N];
void solve() {
  int n, m, k;
  Read(n), Read(m), Read(k);
  for (int i = 1; i <= n; ++i) {
    du[i] = 0;
    pool[i].clear();
  }
  for (int i = 1; i <= m; ++i) {
    Read(u[i]), Read(v[i]);
    ++du[u[i]], ++du[v[i]];
  }
  int cnt = n, sum = 0;
  S = ++cnt, T = ++cnt;
  for (int i = 1; i <= n; ++i) {
    f[i] = 2 * max(du[i] - k, 0);
    add(i, T, f[i]);
    sum += f[i];
  }
  for (int i = 1; i <= m; ++i) {
    int now = ++cnt;
    add(S, now, 1);
    add(now, u[i], 1);
    pre[i] = E.size() - 2;
    add(now, v[i], 1);
  }
  if (sum != Max_flow()) {
    for (int i = 1; i <= m; ++i) printf("0 ");
    putchar('\n');
    init(cnt);
    return;
  }
  for (int i = 1; i <= m; ++i) {
    if (E[pre[i]].cap == E[pre[i]].flow)
      pool[u[i]].push_back(i);
    else
      pool[v[i]].push_back(i);
  }
  sum = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < (signed)pool[i].size(); ++j) {
      if (j & 1)
        bel[pool[i][j]] = bel[pool[i][j - 1]];
      else
        bel[pool[i][j]] = ++sum;
    }
  for (int i = 1; i <= m; ++i) {
    Write(bel[i]);
    putchar(' ');
  }
  putchar('\n');
  init(cnt);
}
int main() {
  int T;
  Read(T);
  while (T--) solve();
  return 0;
}