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 INF = 0x3f3f3f3f;
const int MAXV = 100005;
struct Dinic {
  struct edg {
    int pos, cap, rev;
  };
  int dist[MAXV], pnt[MAXV];
  vector<edg> gph[MAXV];
  void connect(int a, int b, int c) {
    gph[a].push_back({b, c, (int)gph[b].size()});
    gph[b].push_back({a, 0, (int)gph[a].size() - 1});
  }
  bool bfs(int src, int sink) {
    memset(dist, 0, sizeof(dist));
    memset(pnt, 0, sizeof(pnt));
    queue<int> que;
    que.push(src);
    dist[src] = 1;
    while (!que.empty()) {
      int x = que.front();
      que.pop();
      for (auto& e : gph[x]) {
        if (e.cap > 0 && !dist[e.pos]) {
          dist[e.pos] = dist[x] + 1;
          que.push(e.pos);
        }
      }
    }
    return dist[sink];
  }
  int dfs(int x, int sink, int f) {
    if (x == sink) return f;
    for (; pnt[x] < (int)gph[x].size(); pnt[x]++) {
      edg e = gph[x][pnt[x]];
      if (e.cap > 0 && dist[e.pos] == dist[x] + 1) {
        int w = dfs(e.pos, sink, min(f, e.cap));
        if (w) {
          gph[x][pnt[x]].cap -= w;
          gph[e.pos][e.rev].cap += w;
          return w;
        }
      }
    }
    return 0;
  }
  int send(int S, int E) {
    int tot = 0;
    while (bfs(S, E)) {
      int r;
      while ((r = dfs(S, E, 2e9))) tot += r;
    }
    return tot;
  }
};
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  Dinic D;
  vector<pair<int, int>> edges;
  vector<int> degree(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    edges.push_back(make_pair(a, b));
    D.connect(i + 1, m + a, 1);
    D.connect(i + 1, m + b, 1);
    D.connect(0, i + 1, 1);
    degree[a]++, degree[b]++;
  }
  int maxmatch = 0;
  for (int i = 0; i < n; i++) {
    int d = degree[i + 1];
    if (d <= k) continue;
    int required = (d - k) * 2;
    D.connect(m + i + 1, m + n + 1, required);
    maxmatch += required;
  }
  int ans = D.send(0, m + n + 1);
  if (ans != maxmatch) {
    for (int i = 0; i < m; i++) cout << 0 << ' ';
    cout << '\n';
    return;
  }
  vector<int> color(m);
  vector<vector<int>> usethis(n);
  for (int i = 0; i < m; i++) {
    for (auto& e : D.gph[i + 1]) {
      int v = e.pos - m - 1;
      if (!(0 <= v && v < n)) continue;
      if (e.cap) continue;
      usethis[v].push_back(i);
    }
  }
  int c = 1;
  for (int i = 0; i < n; i++) {
    for (size_t j = 0; j < usethis[i].size(); j += 2) {
      color[usethis[i][j]] = color[usethis[i][j + 1]] = c;
      c++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (color[i] == 0) color[i] = c++;
  }
  for (int x : color) cout << x << ' ';
  cout << '\n';
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int TEST;
  cin >> TEST;
  while (TEST--) solve();
}