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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
const int maxnodes = 1005;
struct Edge {
  int from, to, cap, flow, index;
  Edge(int from, int to, int cap, int flow, int index)
      : from(from), to(to), cap(cap), flow(flow), index(index) {}
};
struct PushRelabel {
  int N;
  vector<vector<Edge>> G;
  vector<long long> excess;
  vector<int> dist, active, count;
  queue<int> Q;
  PushRelabel(int N)
      : N(N), G(N), excess(N), dist(N), active(N), count(2 * N) {}
  void AddEdge(int from, int to, int cap) {
    G[from].push_back(Edge(from, to, cap, 0, G[to].size()));
    if (from == to) G[from].back().index++;
    G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1));
  }
  void Enqueue(int v) {
    if (!active[v] && excess[v] > 0) {
      active[v] = true;
      Q.push(v);
    }
  }
  void Push(Edge &e) {
    int amt = (int)(min(excess[e.from], (long long)(e.cap - e.flow)));
    if (dist[e.from] <= dist[e.to] || amt == 0) return;
    e.flow += amt;
    G[e.to][e.index].flow -= amt;
    excess[e.to] += amt;
    excess[e.from] -= amt;
    Enqueue(e.to);
  }
  void Gap(int k) {
    for (int v = 0; v < N; v++) {
      if (dist[v] < k) continue;
      count[dist[v]]--;
      dist[v] = max(dist[v], N + 1);
      count[dist[v]]++;
      Enqueue(v);
    }
  }
  void Relabel(int v) {
    count[dist[v]]--;
    dist[v] = 2 * N;
    for (int i = 0; i < G[v].size(); i++)
      if (G[v][i].cap - G[v][i].flow > 0)
        dist[v] = min(dist[v], dist[G[v][i].to] + 1);
    count[dist[v]]++;
    Enqueue(v);
  }
  void Discharge(int v) {
    for (int i = 0; excess[v] > 0 && i < G[v].size(); i++) Push(G[v][i]);
    if (excess[v] > 0) {
      if (count[dist[v]] == 1)
        Gap(dist[v]);
      else
        Relabel(v);
    }
  }
  long long GetMaxFlow(int s, int t) {
    count[0] = N - 1;
    count[N] = 1;
    dist[s] = N;
    active[s] = active[t] = true;
    for (int i = 0; i < G[s].size(); i++) {
      excess[s] += G[s][i].cap;
      Push(G[s][i]);
    }
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      active[v] = false;
      Discharge(v);
    }
    long long totflow = 0;
    for (int i = 0; i < G[s].size(); i++) totflow += G[s][i].flow;
    return totflow;
  }
};
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tc;
  cin >> tc;
  while (tc--) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<pair<int, int>>> g(n + 1);
    for (int i = 0; i < m; i++) {
      int u, v;
      cin >> u >> v;
      g[u].push_back({v, i + 1});
      g[v].push_back({u, i + 1});
    }
    PushRelabel pr(n + m + 2);
    int s = 0;
    for (int i = 1; i <= n; i++) {
      if (g[i].size() > k) {
        int r = 2 * (g[i].size() - k);
        s += r;
        pr.AddEdge(0, i, r);
        for (auto &it : g[i]) {
          pr.AddEdge(i, it.second + n, 1);
        }
      }
    }
    for (int i = 1; i <= m; i++) {
      pr.AddEdge(i + n, n + m + 1, 1);
    }
    int mflow = pr.GetMaxFlow(0, n + m + 1);
    if (mflow != s) {
      for (int i = 0; i < m; i++) cout << "0 ";
      cout << "\n";
    } else {
      int ans[m + 1];
      memset(ans, -1, sizeof(ans));
      int j = 1;
      for (int i = 1; i <= n; i++) {
        vector<int> local;
        for (auto &it : pr.G[i]) {
          if (it.flow > 0) local.push_back(it.to);
        }
        for (int i = 0; i < local.size(); i += 2) {
          ans[local[i] - n] = j;
          ans[local[i + 1] - n] = j;
          j++;
        }
      }
      for (int i = 1; i <= m; i++) {
        if (ans[i] == -1) {
          ans[i] = j;
          j++;
        }
        cout << ans[i] << " ";
      }
      cout << "\n";
    }
  }
  return 0;
}