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 SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
struct Edge {
  int v, rev, cap;
  Edge(int v, int cap, int rev) : v(v), cap(cap), rev(rev) {}
};
struct MaxFlow {
  vector<vector<Edge> > g;
  vector<int> level;
  queue<int> q;
  int n;
  MaxFlow(int n) : g(n), level(n), n(n) {}
  void addEdge(int u, int v, int cap) {
    Edge e(v, cap, int(g[v].size()));
    Edge r(u, 0, int(g[u].size()));
    g[u].push_back(e);
    g[v].push_back(r);
  }
  int buildLevelGraph(int second, int t) {
    fill(level.begin(), level.end(), -1);
    queue<int> q;
    level[second] = 0;
    q.push(second);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto e : g[u]) {
        if (level[e.v] == -1 && e.cap) {
          level[e.v] = level[u] + 1;
          if (e.v == t) return 1;
          q.push(e.v);
        }
      }
    }
    return 0;
  }
  int blockingFlow(int second, int t, int first) {
    if (second == t || !first) return first;
    int fu = 0;
    for (auto& e : g[second]) {
      if (e.cap && level[e.v] == level[second] + 1) {
        int mincap = blockingFlow(e.v, t, min(e.cap, first - fu));
        g[e.v][e.rev].cap += mincap;
        e.cap -= mincap;
        fu += mincap;
      }
    }
    if (!fu) level[second] = -1;
    return fu;
  }
  int maxflow(int second, int t) {
    int flow = 0;
    while (buildLevelGraph(second, t))
      flow += blockingFlow(second, t, 0x3f3f3f3f);
    return flow;
  }
  vector<int> getEdges(int u) {
    vector<int> res;
    for (auto e : g[u]) {
      if (!e.cap) res.push_back(e.v);
    }
    return res;
  }
};
void test_case() {
  int n, m, k, a, b;
  cin >> n >> m >> k;
  vector<vector<pair<int, int> > > g(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back({b, i});
    g[b].push_back({a, i});
  }
  MaxFlow mf(n + m + 2);
  int second = n + m, t = n + m + 1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int sz = int(g[i].size()) - k;
    if (sz > 0) {
      cnt += 2 * sz;
      mf.addEdge(second, i, 2 * sz);
    }
    for (auto [v, id] : g[i]) mf.addEdge(i, id + n, 1);
  }
  for (int i = 0; i < m; i++) mf.addEdge(i + n, t, 1);
  vector<int> color(m);
  int x = 1;
  if (mf.maxflow(second, t) == cnt) {
    for (int i = 0; i < n; i++) {
      vector<int> edges = mf.getEdges(i);
      for (int j = 0; j < edges.size(); j += 2) {
        color[edges[j] - n] = color[edges[j + 1] - n] = x++;
      }
    }
    for (auto& c : color) {
      if (!c) c = x++;
    }
  }
  for (auto c : color) cout << c << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    test_case();
  }
  return 0;
}