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;
template <typename T>
T input() {
  T res;
  cin >> res;
  {};
  return res;
}
template <typename IT>
void input_seq(IT b, IT e) {
  std::generate(b, e,
                input<typename std::remove_reference<decltype(*b)>::type>);
}
struct edge_t {
  int to;
  int flow;
  int cap;
  int next;
};
int push(int v, int tg, vector<int>& head, vector<edge_t>& edges,
         vector<char>& used) {
  if (v == tg) return 1;
  used[v] = 1;
  for (int ed = head[v]; ed != -1; ed = edges[ed].next) {
    if (edges[ed].flow < edges[ed].cap and not used[edges[ed].to] and
        push(edges[ed].to, tg, head, edges, used)) {
      edges[ed].flow += 1;
      edges[ed ^ 1].flow -= 1;
      return 1;
    }
  }
  return 0;
}
int kukarek(vector<int>& head, vector<edge_t>& edges, vector<char>& used,
            vector<vector<int>>& list, int v, int tg) {
  int OFF_VERT = 2;
  int OFF_EDG = 2 + int((list).size());
  if (v == tg) return 1;
  for (int ed = head[v]; ed != -1; ed = edges[ed].next)
    if (edges[ed].flow > 0 and not used[edges[ed].to] and
        kukarek(head, edges, used, list, edges[ed].to, tg)) {
      edges[ed].flow -= 1;
      edges[ed ^ 1].flow += 1;
      int to = edges[ed].to;
      if (OFF_VERT <= v and v < OFF_EDG and OFF_EDG <= to) {
        list[v - OFF_VERT].push_back(to - OFF_EDG);
      }
      return 1;
    }
  return 0;
}
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  int S = 0;
  int T = 1;
  int OFF_VERT = 2;
  int OFF_EDG = 2 + n;
  vector<int> head(2 + n + m, -1);
  vector<edge_t> edges;
  vector<int> deg(n);
  auto add_edge = [&](int from, int to, int cap) {
    edges.push_back(edge_t{to, 0, cap, head[from]});
    head[from] = int((edges).size()) - 1;
    edges.push_back(edge_t{from, 0, 0, head[to]});
    head[to] = int((edges).size()) - 1;
  };
  for (int i = 0; i != m; ++i) {
    int v = input<int>() - 1;
    int u = input<int>() - 1;
    add_edge(OFF_VERT + v, OFF_EDG + i, 1);
    add_edge(OFF_VERT + u, OFF_EDG + i, 1);
    deg[v] += 1;
    deg[u] += 1;
  }
  for (int i = 0; i != m; ++i) add_edge(OFF_EDG + i, T, 1);
  int need_flow = 0;
  for (int i = 0; i != n; ++i) {
    add_edge(S, OFF_VERT + i, 2 * max(0, deg[i] - k));
    need_flow += 2 * max(0, deg[i] - k);
  }
  int flow = 0;
  while (true) {
    vector<char> used(int((head).size()), false);
    if (push(S, T, head, edges, used))
      flow += 1;
    else
      break;
  }
  if (flow != need_flow) {
    for (int i = 0; i != m; ++i) cout << "0 ";
    cout << "\n";
  } else {
    vector<int> ans(m);
    std::iota(ans.begin(), ans.end(), 1);
    vector<vector<int>> list(n);
    for (int it = 0; it != flow; ++it) {
      vector<char> used(int((head).size()), false);
      kukarek(head, edges, used, list, 0, T);
    }
    for (int v = 0; v != n; ++v) {
      for (int i = 0; i < int((list[v]).size()); i += 2)
        ans[list[v][i + 1]] = ans[list[v][i]];
    }
    for (auto elem : ans) cout << elem << " ";
    cout << "\n";
  }
}
int main() {
  iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (int t = input<int>(); t != 0; --t) {
    solve();
  }
  return 0;
}