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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef int ll;
const ll MAX = 1e3;
const ll mod = 1e4;
const ll inf = 1e9;
struct FlowEdge {
  int v, u;
  int cap, flow = 0;
  FlowEdge(int v, int u, int cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const int flow_inf = 1e9;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, int u, int cap) {
    edges.emplace_back(v, u, cap);
    edges.emplace_back(u, v, 0);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  int dfs(int v, int pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      int tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  int flow() {
    int f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (int pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
int c[MAX], ans[MAX];
vector<ll> adj[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc, n, m, k, s, t, u, v;
  cin >> tc;
  while (tc--) {
    cin >> n >> m >> k;
    s = 0, t = n + m + 1;
    Dinic dinic(n + m + 2, s, t);
    for (ll i = 1; i < (ll)m + 1; i++) {
      cin >> u >> v;
      c[u]++, c[v]++;
      dinic.add_edge(n + i, t, 1);
      dinic.add_edge(u, n + i, 1);
      dinic.add_edge(v, n + i, 1);
    }
    int to = 0;
    for (ll i = 1; i < (ll)n + 1; i++)
      if (c[i] > k) dinic.add_edge(s, i, 2 * (c[i] - k)), to += 2 * (c[i] - k);
    if (dinic.flow() == to) {
      for (FlowEdge it : dinic.edges) {
        if (1 <= it.v && it.v <= n && n + 1 <= it.u && it.u <= n + m &&
            it.flow == 1) {
          adj[it.v].push_back(it.u - n);
        }
      }
      ll col = 1;
      for (ll i = 1; i < (ll)n + 1; i++) {
        for (ll j = 0; j < (ll)adj[i].size(); j += 2)
          ans[adj[i][j]] = ans[adj[i][j + 1]] = col++;
      }
      for (ll i = 1; i < (ll)m + 1; i++)
        if (ans[i] == 0) ans[i] = col++;
    }
    for (ll i = 1; i < (ll)m + 1; i++) cout << ans[i] << " ", ans[i] = 0;
    cout << endl;
    for (ll i = 1; i < (ll)n + 1; i++) adj[i].clear(), c[i] = 0;
  }
  return 0;
}