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>
int debugnum = 0;
using namespace std;
const int MAXN = 600 * 20 + 50;
class Graph {
 public:
  struct Node {
    int C, to, next;
    Node(int C = 0, int to = 0, int next = 0) : C(C), to(to), next(next) { ; }
  } node[MAXN];
  int head[MAXN], nodecnt;
  int degree[MAXN];
  void init(int N, int M) {
    nodecnt = 2;
    for (int i = (0); i < (N + M + 5); i++) head[i] = degree[i] = 0;
    memset(node, 0, sizeof node);
  }
  void add(int a, int b, int C) {
    node[nodecnt] = Node(C, b, head[a]);
    head[a] = nodecnt++;
    node[nodecnt] = Node(0, a, head[b]);
    head[b] = nodecnt++;
  }
  void addarc(int i, int a, int b, int M) {
    add(i, M + a, 1);
    add(i, M + b, 1);
    degree[M + a]++;
    degree[M + b]++;
  }
  int len[MAXN], iter[MAXN];
  int dinicDFS(int now, int T, int Climit = INT_MAX) {
    int k;
    if (now == T) return Climit;
    for (int &ptr = iter[now]; ptr > 0; ptr = node[ptr].next) {
      int &C = node[ptr].C, &to = node[ptr].to;
      if (len[to] == len[now] + 1 && C > 0) {
        if (k = dinicDFS(to, T, min(Climit, C))) {
          node[ptr].C -= k;
          node[ptr ^ 1].C += k;
          return k;
        }
      }
    }
    return 0;
  }
  bool dinicBFS(int s, int t, int N) {
    memset(len, 0, (sizeof(len[0])) * (N + 5));
    queue<int> que;
    que.push(s);
    len[s] = 1;
    while (!que.empty()) {
      int now = que.front();
      que.pop();
      for (int ptr = head[now]; ptr > 0; ptr = node[ptr].next) {
        Node &e = node[ptr];
        if (len[e.to] == 0 && e.C > 0) {
          que.push(e.to);
          len[e.to] = len[now] + 1;
          if (e.to == t) return true;
        }
      }
    }
    return false;
  }
  int dinic(int s, int t, int N) {
    int ret = 0, tmp;
    while (dinicBFS(s, t, N)) {
      copy(head, head + N + 5, iter);
      while (tmp = dinicDFS(s, t)) ret += tmp;
    }
    return ret;
  }
} graph;
vector<int> vec[MAXN];
int color[MAXN];
void solve(int N, int M) {
  for (int i = (0); i < (M + 1); i++) color[i] = 0;
  for (int i = (1); i < (N + 1); i++) vec[i].clear();
  for (int i = (1); i < (M + 1); i++) {
    int pos = graph.head[i];
    for (int ptr = pos; ptr > 0; ptr = graph.node[ptr].next) {
      Graph::Node e = graph.node[ptr];
      if (e.C == 0) {
        int t = e.to - M;
        vec[t].push_back(i);
      }
    }
  }
  int cnt = 2;
  for (int i = (1); i < (N + 1); i++) {
    assert(vec[i].size() % 2 == 0);
    for (int j = (0); j < (vec[i].size()); j++) {
      int e = vec[i][j];
      color[e] = (cnt++) >> 1;
    }
  }
  for (int i = (1); i < (M + 1); i++) {
    if (color[i] == 0) color[i] = (cnt++) >> 1;
    printf("%d%c", color[i], (i == M) ? '\n' : ' ');
  }
}
int main() {
  int N, M, K, T;
  cin >> T;
  while (T--) {
    cin >> N >> M >> K;
    graph.init(N, M);
    const int S = N + M + 1, T = N + M + 2;
    for (int i = (1); i < (M + 1); i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      graph.addarc(i, a, b, M);
      graph.add(S, i, 1);
    }
    bool flag = true;
    long long maxflow = 0;
    for (int i = (M + 1); i < (M + N + 1); i++) {
      int tmp = graph.degree[i];
      if (tmp > 2 * K) {
        flag = false;
        break;
      } else if (tmp <= K)
        continue;
      else
        tmp = (tmp - K) * 2;
      graph.add(i, T, tmp);
      maxflow += tmp;
    }
    int ret = graph.dinic(S, T, N + M + 2);
    if (flag && ret == maxflow) {
      solve(N, M);
    } else
      for (int i = (0); i < (M); i++) printf("0%c", (i != M - 1) ? ' ' : '\n');
  }
  return 0;
}