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;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 2e9 + 5;
struct edge {
  int from, to;
  int f;
};
using graph = vvi;
using edge_list = vector<edge>;
constexpr int back_edge(int i) { return i ^ 1; }
const bool IS_DIRECTED = 1;
void add_edge(graph &g, edge_list &e, int a, int b, int c,
              bool directed = IS_DIRECTED) {
  int index = e.size();
  g[a].push_back(index);
  g[b].push_back(back_edge(index));
  e.push_back({a, b, c});
  e.push_back({b, a, directed ? 0 : c});
}
int level_dfs(graph &g, edge_list &el, vi &level, vi &pointer, int source,
              int sink, int flow = INF) {
  if (source == sink) return flow;
  for (int &idx = pointer[source]; idx < g[source].size(); idx++) {
    int i = g[source][idx];
    edge &e = el[i];
    if (level[e.to] == level[source] + 1 && e.f > 0) {
      int pushed = level_dfs(g, el, level, pointer, e.to, sink, min(flow, e.f));
      if (pushed > 0) {
        el[i].f -= pushed;
        el[back_edge(i)].f += pushed;
        return pushed;
      }
    }
  }
  return 0;
}
bool level_bfs(graph &g, edge_list &el, vi &level, int source, int sink) {
  fill(level.begin(), level.end(), INF);
  level[source] = 0;
  queue<int> q;
  q.push(source);
  while (!q.empty() && level[sink] == INF) {
    int curr = q.front();
    q.pop();
    for (int &i : g[curr]) {
      edge &e = el[i];
      if (e.f > 0 && level[e.to] == INF) {
        level[e.to] = level[curr] + 1;
        q.push(e.to);
      }
    }
  }
  return level[sink] != INF;
}
ll dinic(graph &g, edge_list &el, int source, int sink) {
  vi level(g.size());
  ll flow = 0;
  while (level_bfs(g, el, level, source, sink)) {
    vi pointer(g.size());
    int tmp;
    while ((tmp = level_dfs(g, el, level, pointer, source, sink))) {
      flow += tmp;
    }
  }
  return flow;
}
int main() {
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    graph g(1 + n + m + 1);
    edge_list el;
    int source = 0, sink = n + m + 1;
    vvi adj(n + 1);
    vector<pii> edges(m);
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      edges[i] = {a, b};
      adj[a].push_back(i);
      adj[b].push_back(i);
      add_edge(g, el, (n + 1) + i, sink, 1);
    }
    int to_match = 0;
    for (int i = 1; i <= n; i++)
      if (adj[i].size() > k) {
        int many = (adj[i].size() - k) * 2;
        to_match += many;
        add_edge(g, el, source, i, many);
        for (int x : adj[i]) add_edge(g, el, i, (n + 1) + x, 1);
      }
    vi color(m);
    auto flow = dinic(g, el, source, sink);
    if (flow != to_match) {
      for (int i : color) cout << i << ' ';
      cout << '\n';
      continue;
    }
    int l = 1;
    for (int i = 1; i <= n; i++) {
      int cnt = 0;
      for (int e_i : g[i]) {
        edge &e = el[e_i];
        if (e.f > 0) continue;
        color[e.to - (n + 1)] = l;
        cnt++;
        if (cnt == 2) {
          cnt = 0;
          l++;
        }
      }
    }
    for (int &i : color)
      if (i == 0) i = l++;
    for (int i : color) cout << i << ' ';
    cout << '\n';
  }
  return cout << '\n', 0;
}