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 int maxn = 1200 + 5;
const long long inf = 1e9 + 7;
long long n, m, k;
struct edge {
  int from, to;
  long long flow;
  edge() {}
  edge(int from, int to, long long flow) {
    this->from = from;
    this->to = to;
    this->flow = flow;
  }
};
vector<int> g[maxn];
vector<edge> e;
int dis[maxn];
bool vis[maxn];
long long ans = 0;
int startPoint, endPoint;
int d[maxn];
int tot = 1;
vector<int> son[maxn];
int Son = 0;
int too[maxn];
vector<int> s[maxn];
inline void add(int a, int b, long long c) {
  e.push_back(edge(a, b, c));
  e.push_back(edge(b, a, 0));
  int len = e.size();
  if (a >= 1 && a <= m && b >= m + 1 && b < endPoint) s[b].push_back(len - 2);
  g[a].push_back(len - 2);
  g[b].push_back(len - 1);
  return;
}
bool bfs() {
  memset(dis, -1, sizeof(dis));
  queue<int> que;
  dis[startPoint] = 0;
  que.push(startPoint);
  bool flag = 0;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    int len = g[x].size();
    for (int i = 0; i < len; i++) {
      int toNum = g[x][i];
      int to = e[g[x][i]].to;
      long long flow = e[toNum].flow;
      if (flow > 0 && dis[to] == -1) {
        dis[to] = dis[x] + 1;
        que.push(to);
        if (to == endPoint) flag = 1;
      }
    }
  }
  return flag;
}
long long dfs(int x, long long flow) {
  if (x == endPoint || flow == 0) return flow;
  long long res = 0, f;
  int len = g[x].size();
  for (int i = 0; i < len; i++) {
    int toNum = g[x][i];
    int to = e[toNum].to;
    long long c = e[toNum].flow;
    if (dis[to] == dis[x] + 1 && c > 0) {
      f = dfs(to, min(flow, c));
      if (f <= 0) continue;
      e[toNum].flow -= f;
      e[toNum ^ 1].flow += f;
      res += f;
      flow -= f;
      if (flow == 0) break;
    }
  }
  return res;
}
void maxflow() {
  ans = 0;
  while (bfs()) ans += dfs(startPoint, inf);
}
inline void init() {
  for (int i = 0; i <= endPoint; i++) {
    s[i].clear();
    g[i].clear();
    son[i].clear();
    d[i] = 0;
    too[i] = 0;
  }
  e.clear();
  tot = 1;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%I64d%I64d%I64d", &n, &m, &k);
    startPoint = 0, endPoint = m + n + 1;
    init();
    for (int i = 1; i <= m; i++) {
      add(startPoint, i, 1);
    }
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      add(i, x + m, 1);
      add(i, y + m, 1);
      d[x]++;
      d[y]++;
    }
    long long sum = 0;
    for (int i = 1; i <= n; i++)
      add(m + i, endPoint, max(0LL, 2LL * (d[i] - k))),
          sum += max(2LL * (d[i] - k), 0LL);
    maxflow();
    if (ans == sum) {
      for (int i = m + 1; i < endPoint; i++) {
        for (int j = 0; j < s[i].size(); j++) {
          int to = s[i][j];
          if (e[to].flow == 0) son[i].push_back(e[to].from);
        }
      }
      for (int i = m + 1; i < endPoint; i++) {
        if (son[i].size() == 0)
          continue;
        else {
          int len = son[i].size();
          for (int j = 0; j < len; j += 2) {
            too[son[i][j]] = too[son[i][j + 1]] = tot++;
          }
        }
      }
      for (int i = 1; i <= m; i++) {
        if (!too[i]) {
          too[i] = tot++;
        }
      }
      for (int i = 1; i <= m; i++) printf("%d ", too[i]);
    } else {
      for (int i = 1; i <= m; i++) {
        printf("0 ");
      }
    }
    puts("");
  }
  return 0;
}