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;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
class MaxFlow {
 public:
  int cap[5000], flow[5000];
  int to[5000], prev[5000], last[2000], used[2000], level[2000];
  int V, E;
  MaxFlow(int n) {
    V = n;
    E = 0;
    for (int(i) = 0; (i) < (int)(V); (i)++) last[i] = -1;
  }
  void init(int n, int es) {
    V = n;
    E = 0;
    for (int(i) = 0; (i) < (int)(V); (i)++) last[i] = -1;
    for (int(i) = 0; (i) < (int)(V); (i)++) {
      used[i] = 0;
      level[i] = 0;
    }
    for (int(i) = 0; (i) < (int)(es); (i)++) {
      cap[i] = flow[i] = to[i] = prev[i] = 0;
    }
  }
  void add_edge(int x, int y, int f) {
    cap[E] = f;
    flow[E] = 0;
    to[E] = y;
    prev[E] = last[x];
    last[x] = E;
    E++;
    cap[E] = 0;
    flow[E] = 0;
    to[E] = x;
    prev[E] = last[y];
    last[y] = E;
    E++;
  }
  bool bfs(int s, int t) {
    int i;
    for (int(i) = 0; (i) < (int)(V); (i)++) level[i] = -1;
    queue<int> q;
    q.push(s);
    level[s] = 0;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (i = last[x]; i >= 0; i = prev[i])
        if (level[to[i]] == -1 && cap[i] > flow[i]) {
          q.push(to[i]);
          level[to[i]] = level[x] + 1;
        }
    }
    return (level[t] != -1);
  }
  int dfs(int v, int t, int f) {
    int i;
    if (v == t) return f;
    for (i = used[v]; i >= 0; used[v] = i = prev[i])
      if (level[to[i]] > level[v] && cap[i] > flow[i]) {
        int tmp = dfs(to[i], t, min(f, cap[i] - flow[i]));
        if (tmp > 0) {
          flow[i] += tmp;
          flow[i ^ 1] -= tmp;
          return tmp;
        }
      }
    return 0;
  }
  vector<pair<int, int> > positive_edges() {
    vector<pair<int, int> > ans;
    for (int(i) = 0; (i) < (int)(V); (i)++)
      for (int j = last[i]; j >= 0; j = prev[j])
        if (cap[j] - flow[j] > 0) ans.push_back(make_pair(i, to[j]));
    return ans;
  }
  int maxflow(int s, int t) {
    while (bfs(s, t)) {
      for (int(i) = 0; (i) < (int)(V); (i)++) used[i] = last[i];
      while (dfs(s, t, (1 << 29)) != 0)
        ;
    }
    int ans = 0;
    for (int i = last[s]; i >= 0; i = prev[i]) ans += flow[i];
    return ans;
  }
};
int a[666], b[666], dg[666], A[666];
vector<int> bs[666];
void fmain(int tid) {
  scanf("%d%d%d", &n, &m, &k);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    dg[i] = 0;
    bs[i].clear();
  }
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    scanf("%d%d", a + i, b + i);
    dg[a[i]]++;
    dg[b[i]]++;
    A[i] = 0;
  }
  int S = 0, T = n + m + 1, tt = 0;
  MaxFlow mf = MaxFlow(T + 5);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int fl = max(0, (dg[i] - k) * 2);
    tt += fl;
    mf.add_edge(S, i, fl);
  }
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    mf.add_edge(a[i], n + i, 1);
    mf.add_edge(b[i], n + i, 1);
    mf.add_edge(n + i, T, 1);
  }
  int ans = mf.maxflow(S, T);
  if (ans != tt) {
    for (int(i) = 1; (i) <= (int)(m); (i)++) printf("0 ");
    puts("");
    return;
  }
  for (int(i) = 0; (i) < (int)(mf.V); (i)++)
    for (int j = mf.last[i]; j >= 0; j = mf.prev[j])
      if (mf.flow[j] == 1) {
        if (i <= n && mf.to[j] > n) {
          bs[i].push_back(mf.to[j] - n);
        }
      }
  int cnt = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (!bs[i].empty()) {
      for (int j = 0; j < bs[i].size(); j += 2) {
        A[bs[i][j]] = cnt;
        A[bs[i][j + 1]] = cnt;
        cnt++;
      }
    }
  for (int(i) = 1; (i) <= (int)(m); (i)++)
    if (A[i] == 0) A[i] = cnt++;
  for (int(i) = 1; (i) <= (int)(m); (i)++) printf("%d ", A[i]);
  puts("");
}
int main() {
  int t = 1;
  scanf("%d", &t);
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}