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 long long MAX = 10005;
vector<pair<long long, long long> > v[MAX];
vector<long long> cap(1, 0), capI(1, 0);
long long vis[MAX];
long long cue = 0;
long long prev1[MAX];
long long psi[MAX];
long long N;
void dfs(long long x) {
  if (vis[x] == cue) return;
  vis[x] = cue;
  if (x == N) {
    return;
  }
  long long a, b, c, i, j;
  for (j = 0; j < 5; j++) {
    a = rand() % (v[x].size());
    b = v[x][a].first;
    if (vis[b] == cue) continue;
    c = v[x][a].second;
    if (c < 0 && capI[-c] == 0)
      continue;
    else if (c > 0 && cap[c] == 0)
      continue;
    prev1[b] = x;
    psi[b] = v[x][a].second;
    dfs(b);
    if (vis[N] == cue) return;
  }
  for (auto z : v[x]) {
    b = z.first;
    if (vis[b] == cue) continue;
    c = z.second;
    if (c < 0 && capI[-c] == 0)
      continue;
    else if (c > 0 && cap[c] == 0)
      continue;
    prev1[b] = x;
    psi[b] = z.second;
    dfs(b);
    if (vis[N] == cue) return;
  }
}
vector<long long> g[MAX];
long long U[MAX], V[MAX];
long long deg[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(25);
  long long t, n, a, b, c, d, i, j, m, k;
  cin >> t;
  while (t--) {
    cin >> n >> m >> k;
    bool fl = true;
    for (i = 1; i <= m; i++) {
      cin >> U[i] >> V[i];
      deg[U[i]]++;
      deg[V[i]]++;
    }
    N = n + m + 1;
    long long D = 0;
    long long tto = 0;
    for (i = 1; i <= n; i++) {
      if (deg[i] > 2 * k) {
        fl = false;
      }
      long long my = 2 * (deg[i] - k);
      my = max(my, 0ll);
      ++D;
      v[m + i].push_back({N, D});
      v[N].push_back({m + 1, -D});
      cap.push_back(my);
      capI.push_back(0);
      tto += my;
    }
    if (fl) {
      for (i = 1; i <= m; i++) {
        ++D;
        v[i].push_back({m + U[i], D});
        v[m + U[i]].push_back({i, -D});
        cap.push_back(1);
        capI.push_back(0);
        ++D;
        v[i].push_back({m + V[i], D});
        v[m + V[i]].push_back({i, -D});
        cap.push_back(1);
        capI.push_back(0);
      }
      for (i = 1; i <= m; i++) {
        ++D;
        v[0].push_back({i, D});
        v[i].push_back({0, -D});
        cap.push_back(1);
        capI.push_back(0);
      }
      long long maxf = 0;
      cue = 0;
      while (true) {
        cue++;
        dfs(0);
        if (vis[N] != cue) break;
        a = N;
        maxf++;
        while (a != 0) {
          c = psi[a];
          if (c > 0) {
            cap[c]--;
            capI[c]++;
          } else {
            capI[-c]--;
            cap[-c]++;
          }
          a = prev1[a];
        }
      };
      vector<long long> mye[n + 5];
      long long ans[m];
      if (maxf < tto) {
        for (i = 0; i < m; i++) cout << "0 ";
        cout << "\n";
      } else {
        long long co = 0;
        for (i = 1; i <= m; i++) {
          if (cap[n + 2 * i - 1] == 0) {
            mye[U[i]].push_back(i);
          } else if (cap[n + 2 * i] == 0) {
            mye[V[i]].push_back(i);
          } else
            ans[i] = ++co;
        }
        for (i = 1; i <= n; i++) {
          for (j = 0; j < mye[i].size(); j += 2) {
            ans[mye[i][j]] = ++co;
            ans[mye[i][j + 1]] = co;
          }
        }
        for (i = 1; i <= m; i++) cout << ans[i] << " ";
        cout << "\n";
      }
    } else {
      for (i = 0; i < m; i++) cout << "0 ";
      cout << "\n";
    }
    cap.clear();
    capI.clear();
    cap.push_back(0);
    capI.push_back(0);
    for (i = 0; i <= 4 * (n + m) + 5; i++) {
      v[i].clear();
      vis[i] = 0;
      deg[i] = 0;
    }
  }
  return 0;
}