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 MAXN = 5e5 + 10, MOD = 1e9 + 7;
bool dfs(int a, int L, vector<vector<int>>& g, vector<int>& btoa,
         vector<int>& A, vector<int>& B) {
  if (A[a] != L) return 0;
  A[a] = -1;
  for (int b : g[a])
    if (B[b] == L + 1) {
      B[b] = 0;
      if (btoa[b] == -1 || dfs(btoa[b], L + 1, g, btoa, A, B))
        return btoa[b] = a, 1;
    }
  return 0;
}
int hopcroftKarp(vector<vector<int>>& g, vector<int>& btoa) {
  int res = 0;
  vector<int> A(g.size()), B(btoa.size()), cur, next;
  for (;;) {
    fill(begin(A), end(A), 0);
    fill(begin(B), end(B), 0);
    cur.clear();
    for (int a : btoa)
      if (a != -1) A[a] = -1;
    for (int a = 0; a < (int(g.size())); ++a)
      if (A[a] == 0) cur.push_back(a);
    for (int lay = 1;; lay++) {
      bool islast = 0;
      next.clear();
      for (int a : cur)
        for (int b : g[a]) {
          if (btoa[b] == -1) {
            B[b] = lay;
            islast = 1;
          } else if (btoa[b] != a && !B[b]) {
            B[b] = lay;
            next.push_back(btoa[b]);
          }
        }
      if (islast) break;
      if (next.empty()) return res;
      for (int a : next) A[a] = lay;
      cur.swap(next);
    }
    for (int a = 0; a < (int(g.size())); ++a) res += dfs(a, 0, g, btoa, A, B);
  }
}
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> ed(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b, --a, --b;
    ed[a].push_back(i), ed[b].push_back(i);
  }
  auto deg = [&](int c) -> int { return int(ed[c].size()); };
  auto NO = [&]() {
    while (m--) cout << 0 << ' ';
    cout << '\n';
    return;
  };
  vector<vector<int>> g;
  for (int i = 0; i < n; i++) {
    if (deg(i) < k) continue;
    if (deg(i) > 2 * k) {
      NO();
      return;
    }
    for (int j = 0; j < deg(i) - k; j++)
      for (int rep : {0, 1}) g.push_back(ed[i]);
  }
  vector<int> btoa(m, -1);
  int mx_match = hopcroftKarp(g, btoa);
  if (mx_match != int(g.size())) {
    NO();
    return;
  }
  int c = 100499;
  for (int i = 0; i < m; i++) {
    if (btoa[i] != -1)
      btoa[i] /= 2;
    else
      btoa[i] = c - i;
  }
  for (int i = 0; i < m; i++) cout << btoa[i] + 1 << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  cin >> T;
  while (T--) solve();
}