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 = 5000;
const double INF = 1e12;
const double ep = 1e-8;
int t, N, M, K;
int deg[605];
vector<int> g[605];
struct Edge {
  int from, to;
  double cap, flow;
  Edge(int u, int v, double c, double f) : from(u), to(v), cap(c), flow(f) {}
};
struct Dinic {
  int n, m, s, t;
  vector<Edge> edges;
  vector<int> G[maxn];
  int d[maxn], cur[maxn];
  bool vis[maxn];
  void init(int n) {
    for (int i = 0; i < maxn; i++) G[i].clear();
    edges.clear();
  }
  void add(int from, int to, double cap) {
    edges.push_back(Edge(from, to, cap, 0));
    edges.push_back(Edge(to, from, 0, 0));
    m = edges.size();
    G[from].push_back(m - 2);
    G[to].push_back(m - 1);
  }
  bool BFS() {
    memset(vis, 0, sizeof(vis));
    queue<int> Q;
    Q.push(s);
    d[s] = 0;
    vis[s] = 1;
    while (!Q.empty()) {
      int first = Q.front();
      Q.pop();
      for (int i = 0; i < G[first].size(); i++) {
        Edge& e = edges[G[first][i]];
        if (!vis[e.to] && e.cap - e.flow > ep) {
          vis[e.to] = 1;
          d[e.to] = d[first] + 1;
          Q.push(e.to);
        }
      }
    }
    return vis[t];
  }
  double DFS(int first, double a) {
    if (first == t || a == 0) return a;
    double flow = 0, f;
    for (int& i = cur[first]; i < G[first].size(); i++) {
      Edge& e = edges[G[first][i]];
      if (d[first] + 1 == d[e.to] &&
          (f = DFS(e.to, min(a, e.cap - e.flow))) > 0) {
        e.flow += f;
        edges[G[first][i] ^ 1].flow -= f;
        flow += f;
        a -= f;
        if (a == 0) break;
      }
    }
    return flow;
  }
  double maxFlow(int s, int t) {
    this->s = s;
    this->t = t;
    double flow = 0;
    while (BFS()) {
      memset(cur, 0, sizeof(cur));
      flow += DFS(s, INF);
    }
    return flow;
  }
  void show() {
    for (auto& e : edges) {
      printf("(%d -> %d) => cap = %f , flow = %f\n", e.from, e.to, e.cap,
             e.flow);
    }
  }
  void DFS2(int v) {
    vis[v] = true;
    for (int i = 0; i < G[v].size(); ++i) {
      Edge e = edges[G[v][i]];
      if (!vis[e.to] && e.cap - e.flow > ep) {
        DFS2(e.to);
      }
    }
  }
};
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &N, &M, &K);
    vector<pair<int, int>> edges;
    vector<vector<int>> id(N + 1, vector<int>(N + 1));
    for (int i = 1; i <= N; ++i) deg[i] = 0, g[i].clear();
    for (int i = 1; i <= M; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      edges.emplace_back(u, v);
      ++deg[u];
      ++deg[v];
      id[u][v] = id[v][u] = i;
    }
    int ok = 1;
    for (int i = 1; i <= N && ok; ++i) {
      if (deg[i] > 2 * K) {
        ok = 0;
      }
    }
    if (!ok) {
      for (int i = 1; i <= M; ++i) {
        printf("0 ");
      }
      printf("\n");
    } else {
      Dinic D;
      D.init(N + M + 10);
      int s = N + M + 8, t = N + M + 9;
      int min_edge_merge_needed = 0;
      for (int v = 1; v <= N; ++v) {
        if (deg[v] > K) {
          int r = deg[v] - K;
          D.add(s, v, 2 * r);
          min_edge_merge_needed += 2 * r;
        }
      }
      for (int e = 1; e <= M; ++e) {
        D.add(e + N, t, 1);
        D.add(edges[e - 1].first, e + N, 1);
        D.add(edges[e - 1].second, e + N, 1);
      }
      int ret = D.maxFlow(s, t);
      if (min_edge_merge_needed == ret) {
        vector<int> c(M + 1);
        int cur = 1;
        for (auto& e : D.edges) {
          if (1 <= e.from && e.from <= N && e.to > N && e.to <= N + M) {
            if (e.cap - e.flow == 0) {
              int v = edges[e.to - N - 1].first, u = edges[e.to - N - 1].second;
              g[e.from].push_back(id[v][u]);
            }
          }
        }
        for (int v = 1; v <= N; ++v) {
          for (int i = 0; i < g[v].size(); i += 2) {
            c[g[v][i]] = c[g[v][i + 1]] = cur;
            ++cur;
          }
        }
        for (int e = 1; e <= M; ++e) {
          if (c[e]) continue;
          c[e] = cur;
          ++cur;
        }
        for (int i = 1; i <= M; ++i) {
          printf("%d ", c[i]);
        }
        printf("\n");
      } else {
        for (int i = 1; i <= M; ++i) {
          printf("0 ");
        }
        printf("\n");
      }
    }
  }
}