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;
namespace whatever {
int readu() {
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  int value = ch - '0';
  ch = getchar();
  while (isdigit(ch)) {
    value = value * 10 + ch - '0';
    ch = getchar();
  }
  return value;
}
void writeu(int n) {
  if (n < 10)
    putchar(n + '0');
  else {
    writeu(n / 10);
    putchar(n % 10 + '0');
  }
}
struct edge_type {
  int to, next, cap;
};
edge_type edge[600 * 6 + 600 * 2];
int edge_cnt;
int first_edge[2 + 600 + 600];
void insert(int from, int to, int cap) {
  edge[edge_cnt].to = to;
  edge[edge_cnt].next = first_edge[from];
  edge[edge_cnt].cap = cap;
  first_edge[from] = edge_cnt++;
}
int dis[2 + 600 + 600];
bool bfs(int n) {
  memset(dis, 0, sizeof(int) * n);
  static int q[2 + 600 + 600];
  int first = 0;
  int last = 0;
  q[0] = 0;
  dis[0] = 1;
  while (first <= last) {
    int cur = q[first++];
    if (cur == 1) return true;
    for (int e = first_edge[cur]; e != -1; e = edge[e].next) {
      int to = edge[e].to;
      if (edge[e].cap != 0 && dis[to] == 0) {
        dis[to] = dis[cur] + 1;
        q[++last] = to;
      }
    }
  }
  return false;
}
int cur_edge[2 + 600 + 600];
int dfs(int cur, int max_flow) {
  if (cur == 1) return max_flow;
  int cur_flow = 0;
  for (int &e = cur_edge[cur]; e != -1; e = edge[e].next) {
    int to = edge[e].to;
    if (edge[e].cap != 0 && dis[to] == dis[cur] + 1) {
      int new_flow = dfs(to, min(max_flow - cur_flow, edge[e].cap));
      edge[e].cap -= new_flow;
      edge[e ^ 1].cap += new_flow;
      cur_flow += new_flow;
      if (cur_flow == max_flow) return cur_flow;
    }
  }
  dis[cur] = 0;
  return cur_flow;
}
void run() {
  int t = readu();
  while (--t != -1) {
    edge_cnt = 0;
    int n = readu();
    int m = readu();
    int k = readu();
    memset(first_edge, -1, sizeof(int) * (2 + n + m));
    static int cnt[601];
    memset(cnt, 0, sizeof(int) * (n + 1));
    for (int i = n + 2; i < n + 2 + m; ++i) {
      int a = readu();
      int b = readu();
      insert(a + 1, i, 1);
      insert(i, a + 1, 0);
      insert(b + 1, i, 1);
      insert(i, b + 1, 0);
      insert(i, 1, 1);
      insert(1, i, 0);
      ++cnt[a];
      ++cnt[b];
    }
    int result = 0;
    for (int i = 2; i < n + 2; ++i)
      if (cnt[i - 1] > k) {
        result += (cnt[i - 1] - k) * 2;
        insert(0, i, (cnt[i - 1] - k) * 2);
        insert(i, 0, 0);
      }
    while (bfs(2 + n + m)) {
      memcpy(cur_edge, first_edge, sizeof(int) * (2 + n + m));
      result -= dfs(0, 1 << 30);
    }
    assert(result >= 0);
    if (result == 0) {
      static int index[600];
      memset(index, 0, sizeof(int) * m);
      int cur_index = 0;
      bool partial = false;
      for (int i = 2; i < n + 2; ++i)
        if (cnt[i - 1] > k) {
          for (int e = first_edge[i]; e != -1; e = edge[e].next) {
            int to = edge[e].to;
            if (to != 0 && edge[e].cap == 0) {
              assert(index[to - (n + 2)] == 0);
              if (!partial) ++cur_index;
              index[to - (n + 2)] = cur_index;
              partial = !partial;
            }
          }
        }
      assert(!partial);
      for (int i = 0; i < m; ++i) {
        writeu(index[i] == 0 ? ++cur_index : index[i]);
        putchar(' ');
      }
      putchar('\n');
    } else {
      while (--m != -1) {
        putchar('0');
        putchar(' ');
      }
      putchar('\n');
    }
  }
}
}  // namespace whatever
int main() { whatever::run(); }