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;
class dinic_flow {
 public:
  struct edge {
    int to, rev, cap;
    edge(int to = 0, int rev = 0, int cap = 0) : to(to), rev(rev), cap(cap) {}
  };
  vector<vector<edge> > g;
  vector<vector<edge>::iterator> nowi;
  vector<int> dist;
  int nodes, src, dst;
  queue<int> q;
  void init(int _nodes) {
    nodes = _nodes;
    g.resize(_nodes);
    nowi.resize(_nodes);
    for (int i = 0; i < _nodes; i++) g[i].clear();
    dist.resize(_nodes);
  }
  void add_Edge(int _from, int _to, int _cap) {
    g[_from].push_back(edge(_to, g[_to].size(), _cap));
    g[_to].push_back(edge(_from, g[_from].size() - 1, 0));
  }
  bool dinic_bfs() {
    fill(dist.begin(), dist.end(), -1);
    dist[src] = 0;
    q.push(src);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < g[u].size(); i++) {
        edge e = g[u][i];
        if (e.cap) {
          int v = e.to;
          if (dist[v] < 0) dist[v] = dist[u] + 1, q.push(v);
        }
      }
    }
    return dist[dst] >= 0;
  }
  int dinic_dfs(int u, int f) {
    if (u == dst) return f;
    int ret = 0;
    for (vector<edge>::iterator &it = nowi[u]; it != g[u].end(); it++)
      if (it->cap) {
        int v = it->to;
        if (dist[v] == dist[u] + 1) {
          int tmp = dinic_dfs(v, min(f, it->cap));
          it->cap -= tmp, f -= tmp, ret += tmp, g[v][it->rev].cap += tmp;
          if (!f) return ret;
        }
      }
    return ret;
  }
  int maxFlow(int _src, int _dst) {
    src = _src, dst = _dst;
    int flow = 0;
    while (dinic_bfs()) {
      for (int i = 0; i < nodes; i++) nowi[i] = g[i].begin();
      flow += dinic_dfs(_src, 1e9);
    }
    return flow;
  }
} D;
int d[666], c[666];
vector<int> v[666];
int main() {
  int t, n, m, k;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d", &n, &m, &k);
    memset(d, 0, sizeof d);
    D.init(n + m + 10);
    int S = 0, T = n + m + 1;
    for (int i = 1, x, y; i <= m; i++) {
      scanf("%d%d", &x, &y);
      d[x]++;
      d[y]++;
      D.add_Edge(x, n + i, 1);
      D.add_Edge(y, n + i, 1);
      D.add_Edge(n + i, T, 1);
    }
    int tot = 0;
    for (int i = 1; i <= n; i++) {
      int flw = 2 * max(0, d[i] - k);
      tot += flw;
      D.add_Edge(S, i, flw);
    }
    int mxflw = D.maxFlow(S, T);
    if (mxflw != tot) {
      for (int i = 1; i <= m; i++) printf("%d ", 0);
      puts("");
      continue;
    }
    for (int i = 1; i <= n; i++) v[i].clear();
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < D.g[i].size(); j++) {
        int e = D.g[i][j].to, c = D.g[i][j].cap;
        if (e != S && c == 0) v[i].push_back(e - n);
      }
    }
    int cnt = 0;
    memset(c, 0, sizeof c);
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < v[i].size(); j += 2) {
        ++cnt;
        c[v[i][j]] = cnt;
        c[v[i][j + 1]] = cnt;
      }
    }
    for (int i = 1; i <= m; i++) {
      if (!c[i])
        printf("%d ", ++cnt);
      else
        printf("%d ", c[i]);
    }
    puts("");
  }
}