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 = 1e5 + 10, M = 2000, mod = 998244353;
int to[N], prv[N], head[M], ecnt;
long long d[N], cap[N];
int ptr[M];
void add_edge(int x, int y, long long c) {
  to[ecnt] = y, cap[ecnt] = c, prv[ecnt] = head[x], head[x] = ecnt++;
  c = 0;
  swap(x, y);
  to[ecnt] = y, cap[ecnt] = c, prv[ecnt] = head[x], head[x] = ecnt++;
}
bool bfs(int s, int t) {
  memset(d, 0, sizeof d);
  d[s] = 1;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int x = q.front();
    q.pop();
    if (x == t) return 1;
    for (int e = head[x]; e != -1; e = prv[e]) {
      int v = to[e];
      if (!cap[e] || d[v]) continue;
      d[v] = d[x] + 1;
      q.push(v);
    }
  }
  return 0;
}
long long dfs(int s, int t, long long f) {
  if (s == t) return f;
  long long ans = 0;
  for (int& e = ptr[s]; e != -1; e = prv[e]) {
    if (!cap[e] || d[to[e]] != d[s] + 1) continue;
    long long x = dfs(to[e], t, min(f, cap[e]));
    ans += x;
    cap[e] -= x;
    cap[e ^ 1] += x;
    f -= x;
    if (!f) break;
  }
  return ans;
}
long long max_flow(int s, int t) {
  long long ans = 0;
  while (bfs(s, t)) {
    memcpy(ptr, head, sizeof head);
    ans += dfs(s, t, 1e18);
  }
  return ans;
}
int x[N], y[N], ans[N], id[N][2];
int deg[N];
vector<int> v[N];
void solve() {
  memset(head, -1, sizeof head);
  ecnt = 0;
  int n, m, k;
  int s = M - 1, t = M - 2, sum = 0;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) deg[i] = 0, v[i].clear();
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
    ans[i] = -1;
    deg[x[i]]++, deg[y[i]]++;
    add_edge(i + n, t, 1);
    id[i][0] = ecnt;
    add_edge(x[i], i + n, 1);
    id[i][1] = ecnt;
    add_edge(y[i], i + n, 1);
  }
  for (int i = 0; i < n; i++) {
    int x = max(0, 2 * (deg[i] - k));
    if (x) add_edge(s, i, x);
    sum += x;
  }
  if (max_flow(s, t) < sum) {
    for (int i = 0; i < m; i++) cout << 0 << ' ';
    cout << '\n';
    return;
  }
  for (int i = 0; i < m; i++) {
    if (!cap[id[i][0]]) v[x[i]].push_back(i);
    if (!cap[id[i][1]]) v[y[i]].push_back(i);
  }
  int xx = 1;
  for (int i = 0; i < n; i++) {
    while (v[i].size()) {
      int x = v[i].back();
      v[i].pop_back();
      int y = v[i].back();
      v[i].pop_back();
      ans[x] = ans[y] = xx++;
    }
  }
  for (int i = 0; i < m; i++) cout << (ans[i] == -1 ? xx++ : ans[i]) << ' ';
  cout << endl;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}