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;
struct Dinic {
  struct Edge {
    int to, cap, flow, nxt;
  };
  vector<Edge> edges;
  vector<int> graph, at, dist;
  map<pair<int, int>, int> where;
  int src = 0, dest = 1;
  Dinic(int n) : graph(n, -1), dist(n, -1) {}
  bool getTaken(int from, int to) {
    return edges[where[{from, to}]].cap == edges[where[{from, to}]].flow;
  }
  void add_edge(int from, int to, int cap) {
    where[{from, to}] = edges.size();
    edges.push_back(Edge{to, cap, 0, graph[from]});
    graph[from] = edges.size() - 1;
  }
  void AddEdge(int from, int to, int cap) {
    add_edge(from, to, cap);
    add_edge(to, from, 0);
  }
  bool bfs() {
    queue<int> q;
    fill(dist.begin(), dist.end(), -1);
    dist[src] = 0;
    q.push(src);
    while (!q.empty()) {
      int node = q.front();
      q.pop();
      for (int i = graph[node]; i >= 0; i = edges[i].nxt) {
        const auto &e = edges[i];
        if (dist[e.to] == -1 && e.flow < e.cap) {
          dist[e.to] = dist[node] + 1;
          q.push(e.to);
        }
      }
    }
    return dist[dest] != -1;
  }
  int dfs(int node, int flow) {
    if (flow == 0) return 0;
    if (node == dest) return flow;
    while (at[node] != -1) {
      int eid = at[node];
      const auto &e = edges[eid];
      if (dist[e.to] == dist[node] + 1) {
        if (int ret = dfs(e.to, min(flow, e.cap - e.flow))) {
          edges[eid].flow += ret;
          edges[eid ^ 1].flow -= ret;
          return ret;
        }
      }
      at[node] = e.nxt;
    }
    return 0;
  }
  int Compute(int src, int dest) {
    this->src = src;
    this->dest = dest;
    int ret = 0;
    while (bfs()) {
      at = graph;
      while (int flow = dfs(src, 2e9)) ret += flow;
    }
    return ret;
  }
};
vector<int> graph[1000];
vector<pair<int, int>> edges;
vector<int> needed(1000);
vector<int> colors(1000);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n, m, k, sumOfNeeded = 0;
    cin >> n >> m >> k;
    int source = 0;
    int destination = n + m + 1;
    Dinic *myFlow = new Dinic(n + m + 2);
    for (int i = 1; i <= n; ++i) {
      graph[i].clear();
      needed[i] = 0;
    }
    for (int i = 0; i < m; ++i) colors[i] = 0;
    edges.clear();
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      edges.push_back({x, y});
      graph[x].push_back(i);
      graph[y].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
      needed[i] = max(0, (int)graph[i].size() - k);
      needed[i] <<= 1;
      sumOfNeeded += needed[i];
      myFlow->AddEdge(source, i, needed[i]);
      for (auto x : graph[i]) {
        myFlow->AddEdge(i, n + x + 1, 1);
      }
    }
    for (int i = 1; i <= m; ++i) {
      myFlow->AddEdge(n + i, destination, 1);
    }
    int maximumFlow = myFlow->Compute(source, destination);
    if (maximumFlow == sumOfNeeded) {
      int currentColor = 1;
      int used = 0;
      for (int i = 1; i <= n; ++i) {
        for (auto x : graph[i]) {
          if (myFlow->getTaken(i, n + x + 1)) {
            colors[x] = currentColor;
            used += 1;
            if (used == 2) {
              currentColor += 1;
              used = 0;
            }
          }
        }
      }
      used = 0;
      currentColor += 1;
      for (int i = 0; i < m; ++i) {
        if (colors[i]) continue;
        colors[i] = currentColor;
        currentColor += 1;
      }
    }
    for (int i = 0; i < m; ++i) {
      cout << colors[i] << ' ';
    }
    cout << '\n';
  }
}