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 INF = 0x3f3f3f3f;
class edge {
 public:
  int e, nxt, cap;
  edge(int e1 = -1, int nxt1 = -1, int cap1 = 0) {
    e = e1, nxt = nxt1, cap = cap1;
  }
};
int S, T, n, m, k, sum;
int dep[1210];
bool vis[1210];
class graph {
 public:
  edge g[3000000];
  int head[1210], tmpcnt;
  int cur[1210];
  void init() {
    memset(head, 255, sizeof(head));
    tmpcnt = 0;
  }
  void addedge(int s, int e, int cap) {
    if (cap == 0) return;
    g[tmpcnt] = edge(e, head[s], cap), head[s] = tmpcnt++;
    g[tmpcnt] = edge(s, head[e], 0), head[e] = tmpcnt++;
  }
  bool bfs() {
    memset(vis, 0, sizeof(vis));
    memset(dep, 0, sizeof(dep));
    queue<int> q;
    q.push(S);
    vis[S] = 1;
    while (!q.empty()) {
      int fr = q.front();
      q.pop();
      for (int i = head[fr]; i != -1; i = g[i].nxt) {
        if (g[i].cap > 0 && !vis[g[i].e]) {
          dep[g[i].e] = dep[fr] + 1;
          vis[g[i].e] = 1;
          q.push(g[i].e);
        }
      }
    }
    return vis[T];
  }
  int dfs(int np, int maxflow) {
    int f;
    int flow = 0;
    if (np == T || !maxflow) return maxflow;
    for (int i = cur[np]; i != -1; i = g[i].nxt) {
      cur[np] = i;
      if (g[i].cap > 0 && dep[g[i].e] == dep[np] + 1 &&
          (f = dfs(g[i].e, min(g[i].cap, maxflow))) > 0) {
        g[i].cap -= f;
        g[i ^ 1].cap += f;
        flow += f;
        maxflow -= f;
        if (!maxflow) break;
      }
    }
    return flow;
  }
  int dinic() {
    int out = 0;
    while (bfs()) memcpy(cur, head, sizeof(cur)), out += dfs(S, INF);
    return out;
  }
} G;
int times, s[610], e[610], deg[610], ans[610];
vector<int> ch[610];
inline void fail() {
  for (int i = 1; i <= m; i++) printf("0 ");
  puts("");
}
void solve() {
  scanf("%d%d%d", &n, &m, &k);
  memset(deg, 0, sizeof(deg));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s[i], &e[i]);
    deg[s[i]]++;
    deg[e[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] > 2 * k) return fail();
  G.init();
  S = n + m + 1;
  T = n + m + 2;
  sum = 0;
  for (int i = 1; i <= n; i++) {
    if (deg[i] > k) {
      G.addedge(S, i, 2 * (deg[i] - k));
      sum += 2 * (deg[i] - k);
    }
  }
  for (int i = 1; i <= m; i++) {
    G.addedge(i + n, T, 1);
    G.addedge(s[i], i + n, 1);
    G.addedge(e[i], i + n, 1);
  }
  int tmp = G.dinic();
  if (tmp < sum) return fail();
  for (int i = 1; i <= n; i++) ch[i].clear();
  int ecnt = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = G.head[i + n]; j != -1; j = G.g[j].nxt) {
      if (G.g[j].e <= n && G.g[j].cap) {
        ch[G.g[j].e].push_back(i);
        break;
      }
    }
  }
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < ch[i].size(); j += 2) {
      ans[ch[i][j]] = ans[ch[i][j + 1]] = ++ecnt;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (ans[i])
      printf("%d ", ans[i]);
    else
      printf("%d ", ++ecnt);
  }
  puts("");
}
int main() {
  scanf("%d", &times);
  while (times--) solve();
  return 0;
}