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 DINIC {
const int MAXN = 1222;
struct edg {
  int pos, cap, rev;
};
vector<edg> gph[MAXN];
void clear() {
  for (int i = 0; i < MAXN; i++) gph[i].clear();
}
void add_edge(int s, int e, int x) {
  gph[s].push_back({e, x, (int)gph[e].size()});
  gph[e].push_back({s, 0, (int)gph[s].size() - 1});
}
int dis[MAXN], pnt[MAXN];
bool bfs(int src, int sink) {
  memset(dis, 0, sizeof dis);
  memset(pnt, 0, sizeof pnt);
  queue<int> que;
  que.push(src);
  dis[src] = 1;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (auto &e : gph[x]) {
      if (e.cap > 0 && !dis[e.pos]) {
        dis[e.pos] = dis[x] + 1;
        que.push(e.pos);
      }
    }
  }
  return dis[sink] > 0;
}
int dfs(int x, int sink, int f) {
  if (x == sink) return f;
  for (; pnt[x] < gph[x].size(); pnt[x]++) {
    edg e = gph[x][pnt[x]];
    if (e.cap > 0 && dis[e.pos] == dis[x] + 1) {
      int w = dfs(e.pos, sink, min(f, e.cap));
      if (w) {
        gph[x][pnt[x]].cap -= w;
        gph[e.pos][e.rev].cap += w;
        return w;
      }
    }
  }
  return 0;
}
long long match(int src, int sink) {
  long long ret = 0;
  while (bfs(src, sink)) {
    int r;
    while ((r = dfs(src, sink, 2e9))) ret += r;
  }
  return ret;
}
};  // namespace DINIC
int deg[610], p[610];
int col[610];
pair<int, int> a[1000];
void solve() {
  int n, m, k, i;
  scanf("%d%d%d", &n, &m, &k);
  DINIC::clear();
  memset(deg, 0, sizeof(deg));
  for (int i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second;
    deg[a[i].first]++;
    deg[a[i].second]++;
    DINIC::add_edge(a[i].first, i + n + 1, 1);
    DINIC::add_edge(a[i].second, i + n + 1, 1);
    DINIC::add_edge(i + n + 1, n + m + 1, 1);
  }
  for (int i = 1; i <= n; i++) {
    p[i] = max(deg[i] - k, 0);
    DINIC::add_edge(0, i, p[i] * 2);
  }
  int sum = accumulate(p + 1, p + n + 1, 0) * 2;
  if (DINIC::match(0, n + m + 1) != sum) {
    for (int i = 1; i <= m; i++) printf("0 ");
    puts("");
    return;
  }
  for (int i = 0; i < m; i++) col[i] = i + 1;
  for (int i = 1; i <= n; i++) {
    vector<int> v;
    for (auto &j : DINIC::gph[i]) {
      if (j.pos == 0) continue;
      if (j.cap == 0) v.push_back(j.pos - n - 1);
    }
    for (int i = 0; i < v.size(); i += 2) {
      col[v[i + 1]] = col[v[i]];
    }
  }
  for (int i = 0; i < m; i++) printf("%d ", col[i]);
  puts("");
}
int main() {
  int t, i;
  scanf("%d", &t);
  for (i = 0; i < t; i++) solve();
  return 0;
}