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 
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct Matching {
  int n;
  vector<int> matchL, matchR, dist;
  vector<bool> seen;
  vector<vector<int> > ke;
  Matching(int n)
      : n(n),
        matchL(n + 1),
        matchR(n + 1),
        dist(n + 1),
        seen(n + 1, false),
        ke(n + 1) {}
  void addEdge(int u, int v) { ke[u].push_back(v); }
  bool bfs() {
    queue<int> qu;
    for (int u = 1; u <= n; ++u)
      if (!matchL[u]) {
        dist[u] = 0;
        qu.push(u);
      } else
        dist[u] = inf;
    dist[0] = inf;
    while (!qu.empty()) {
      int u = qu.front();
      qu.pop();
      for (__typeof(ke[u].begin()) v = ke[u].begin(); v != ke[u].end(); ++v) {
        if (dist[matchR[*v]] == inf) {
          dist[matchR[*v]] = dist[u] + 1;
          qu.push(matchR[*v]);
        }
      }
    }
    return dist[0] != inf;
  }
  bool dfs(int u) {
    if (u) {
      for (__typeof(ke[u].begin()) v = ke[u].begin(); v != ke[u].end(); ++v)
        if (dist[matchR[*v]] == dist[u] + 1 && dfs(matchR[*v])) {
          matchL[u] = *v;
          matchR[*v] = u;
          return true;
        }
      dist[u] = inf;
      return false;
    }
    return true;
  }
  int match() {
    int res = 0;
    while (bfs()) {
      for (int u = 1; u <= n; ++u)
        if (!matchL[u])
          if (dfs(u)) ++res;
    }
    return res;
  }
};
int n, m, k;
int from[605], to[605];
int need[605], sneed;
int ans[605];
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int ntest;
  cin >> ntest;
  while (ntest--) {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) need[i] = 0;
    for (int i = 1; i <= m; ++i) {
      cin >> from[i] >> to[i];
      ++need[from[i]];
      ++need[to[i]];
    }
    sneed = 0;
    for (int i = 1; i <= n; ++i) {
      need[i] = 2 * max(0, need[i] - k);
      sneed += need[i];
    }
    if (sneed > m) {
      for (int i = 1; i <= m; ++i) cout << 0 << ' ';
      cout << '\n';
      continue;
    }
    Matching G(m);
    for (int i = 1; i <= n; ++i) need[i] += need[i - 1];
    for (int i = 1; i <= m; ++i) {
      int u = from[i], v = to[i];
      for (int j = need[u - 1] + 1; j <= need[u]; ++j) G.addEdge(i, j);
      for (int j = need[v - 1] + 1; j <= need[v]; ++j) G.addEdge(i, j);
    }
    int cnt = G.match();
    if (cnt < sneed) {
      for (int i = 1; i <= m; ++i) cout << 0 << ' ';
      cout << '\n';
      continue;
    }
    for (int i = 1; i <= m; ++i) ans[i] = 0;
    int cur = 1;
    vector<int> vec(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
      for (int j = need[i - 1] + 1; j <= need[i]; ++j) {
        int id = G.matchR[j];
        if (vec[i]) {
          ans[id] = ans[vec[i]] = cur++;
          vec[i] = 0;
        } else
          vec[i] = id;
      }
    }
    for (int i = 1; i <= m; ++i)
      if (!ans[i]) ans[i] = cur++;
    for (int i = 1; i <= m; ++i) cout << ans[i] << ' ';
    cout << '\n';
  }
  return 0;
}
