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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 101010;
const int N = 15000;
struct Edge {
  int v, to, cap, flow;
  Edge() : v(), to(), cap(), flow() {}
  Edge(int _v, int _to, int _cap) : v(_v), to(_to), cap(_cap), flow(0) {}
};
Edge ed[N];
int edSz;
vector<int> g[N];
int S, T;
int n, m;
int ans[N];
vector<int> edForV[N];
int deg[N];
int dist[N];
int q[N];
int topQ;
int idx[N];
void addEdge(int v, int u, int cap) {
  ed[edSz] = Edge(v, u, cap);
  g[v].push_back(edSz++);
  ed[edSz] = Edge(u, v, 0);
  g[u].push_back(edSz++);
}
void clear() {
  edSz = 0;
  for (int i = 0; i <= T; i++) g[i].clear();
  for (int i = 0; i < n; i++) {
    edForV[i].clear();
    deg[i] = 0;
  }
}
bool BFS() {
  for (int i = 0; i <= T; i++) dist[i] = INF;
  dist[S] = 0;
  topQ = 0;
  q[topQ++] = S;
  for (int i = 0; i < topQ; i++) {
    int v = q[i];
    for (int id : g[v]) {
      Edge e = ed[id];
      if (e.cap == e.flow) continue;
      int to = e.to;
      if (dist[to] <= dist[v] + 1) continue;
      dist[to] = dist[v] + 1;
      q[topQ++] = to;
    }
  }
  return dist[T] < INF;
}
int dfs(int v, int flow) {
  if (v == T || flow == 0) return flow;
  int res = 0;
  for (int &i = idx[v]; i < (int)g[v].size(); i++) {
    int id = g[v][i];
    Edge e = ed[id];
    int to = e.to;
    if (dist[to] != dist[v] + 1) continue;
    int df = dfs(to, min(flow, e.cap - e.flow));
    res += df;
    flow -= df;
    ed[id].flow += df;
    ed[id ^ 1].flow -= df;
    if (flow == 0) return res;
  }
  return res;
}
int Flow() {
  int res = 0;
  while (BFS()) {
    for (int i = 0; i <= T; i++) idx[i] = 0;
    res += dfs(S, INF);
  }
  return res;
}
void printAns() {
  for (int i = 0; i < edSz; i++) {
    if (ed[i].flow <= 0) continue;
    int v = ed[i].v, u = ed[i].to;
    if (v >= n || u < n || u >= n + m) continue;
    edForV[v].push_back(u - n);
  }
  for (int i = 0; i < m; i++) ans[i] = 0;
  int id = 1;
  for (int v = 0; v < n; v++) {
    for (int i = 0; i < (int)edForV[v].size(); i++) {
      ans[edForV[v][i]] = id;
      if (i & 1) id++;
    }
  }
  for (int i = 0; i < m; i++)
    if (ans[i])
      printf("%d ", ans[i]);
    else
      printf("%d ", id++);
  printf("\n");
}
void solve() {
  clear();
  int k;
  scanf("%d%d%d", &n, &m, &k);
  S = n + m;
  T = S + 1;
  for (int i = 0; i < m; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    deg[v]++;
    deg[u]++;
    addEdge(v, n + i, 1);
    addEdge(u, n + i, 1);
    addEdge(n + i, T, 1);
  }
  bool bad = false;
  int wantFlow = 0;
  for (int i = 0; !bad && i < n; i++) {
    if (deg[i] > 2 * k) bad = true;
    if (deg[i] > k) addEdge(S, i, 2 * (deg[i] - k));
    wantFlow += max(0, 2 * (deg[i] - k));
  }
  if (bad || Flow() != wantFlow) {
    for (int i = 0; i < m; i++) printf("0 ");
    printf("\n");
    return;
  }
  printAns();
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}