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 MAXO = 1e9;
int node, edge;
int src, des;
vector<int> adjl[(610 + 610)];
vector<int> rc[(610 + 610)];
vector<int> rev_idx[(610 + 610)];
void add_edge(int u, int v, int w) {
  adjl[u].push_back(v);
  adjl[v].push_back(u);
  rc[u].push_back(w);
  rc[v].push_back(0);
  rev_idx[u].push_back(adjl[v].size() - 1);
  rev_idx[v].push_back(adjl[u].size() - 1);
}
void init_flow() {
  for (int i = 0; i <= node; i++) {
    adjl[i].clear();
    rc[i].clear();
    rev_idx[i].clear();
  }
}
int lev[(610 + 610)];
int vis[(610 + 610)];
bool dinic_bfs() {
  memset(vis, 0, sizeof(vis));
  memset(lev, 0, sizeof(lev));
  lev[src] = 0;
  vis[src] = 1;
  queue<int> myq;
  myq.push(src);
  while (!myq.empty()) {
    int u = myq.front();
    myq.pop();
    int sz = adjl[u].size();
    for (int i = 0; i <= sz - 1; i++) {
      int v = adjl[u][i];
      if (rc[u][i] == 0) {
        continue;
      }
      if (vis[v] == 0) {
        vis[v] = 1;
        lev[v] = lev[u] + 1;
        myq.push(v);
      }
    }
  }
  if (vis[des]) {
    return 1;
  }
  return 0;
}
int shuru[(610 + 610)];
int dinic_dfs(int u, int flow) {
  if (u == des) {
    return flow;
  }
  for (int i = shuru[u]; i <= (int)adjl[u].size() - 1; i++) {
    shuru[u] = i;
    int v = adjl[u][i];
    if ((lev[v] == lev[u] + 1) && (rc[u][i])) {
      int ff = dinic_dfs(v, min(flow, rc[u][i]));
      if (ff) {
        rc[u][i] -= ff;
        rc[v][rev_idx[u][i]] += ff;
        return ff;
      }
    }
  }
  shuru[u] = adjl[u].size();
  return 0;
}
int dinic() {
  int ans = 0;
  while (dinic_bfs()) {
    memset(shuru, 0, sizeof(shuru));
    while (1) {
      int ff = dinic_dfs(src, MAXO);
      if (ff == 0) break;
      ans += ff;
    }
  }
  return ans;
}
int d[(610 + 610)], ans[(610 + 610)];
vector<int> took[(610 + 610)];
void solve() {
  int n, m, k, u, v, c = 0;
  cin >> n >> m >> k;
  src = 0;
  node = des = n + m + 1;
  init_flow();
  memset(d, 0, sizeof(d));
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= m; i++) add_edge(src, i + n, 1);
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    add_edge(i + n, u, 1);
    add_edge(i + n, v, 1);
    d[u]++;
    d[v]++;
  }
  for (int i = 1; i <= n; i++)
    if (d[i] > k) add_edge(i, des, (d[i] - k) * 2), c += (d[i] - k) * 2;
  if (dinic() == c) {
    for (int i = 0; i <= n; i++) took[i].clear();
    for (int x = 1; x <= m; x++) {
      u = x + n;
      for (int i = 0; i <= (int)adjl[u].size() - 1; i++) {
        int v = adjl[u][i];
        if (rc[u][i] == 0 && v >= 1 && v <= n) took[v].push_back(x);
      }
    }
    int id = 1;
    for (int u = 1; u <= n; u++) {
      for (int i = 0; i <= (int)took[u].size() - 1; i++) {
        int p = took[u][i];
        ans[p] = id;
        if (i & 1) id++;
      }
    }
    for (int i = 1; i <= m; i++)
      if (!ans[i]) ans[i] = id++;
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << ' ';
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int tc;
  cin >> tc;
  for (int tt = 1; tt <= tc; tt++) solve();
  return 0;
}