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 FlowEdge {
  int v, u;
  long long cap, flow = 0;
  FlowEdge(int v, int u, long long cap) : v(v), u(u), cap(cap) {}
};
struct Dinic {
  const long long flow_inf = 1e18;
  vector<FlowEdge> edges;
  vector<vector<int>> adj;
  int n, m = 0;
  int s, t;
  int vis[10000] = {0};
  vector<int> level, ptr;
  queue<int> q;
  Dinic(int n, int s, int t) : n(n), s(s), t(t) {
    adj.resize(n);
    level.resize(n);
    ptr.resize(n);
  }
  void add_edge(int v, int u, long long cap) {
    edges.emplace_back(v, u, cap);
    edges.emplace_back(u, v, 0);
    adj[v].push_back(m);
    adj[u].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int id : adj[v]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (level[edges[id].u] != -1) continue;
        level[edges[id].u] = level[v] + 1;
        q.push(edges[id].u);
      }
    }
    return level[t] != -1;
  }
  long long dfs(int v, long long pushed) {
    if (pushed == 0) return 0;
    if (v == t) return pushed;
    for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {
      int id = adj[v][cid];
      int u = edges[id].u;
      if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)
        continue;
      long long tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  void dfs2(int s) {
    vis[s] = 1;
    for (int id : adj[s]) {
      int u = edges[id].u;
      if (!vis[u] && edges[id].flow < edges[id].cap) dfs2(u);
    }
  }
  long long flow() {
    long long f = 0;
    while (true) {
      fill(level.begin(), level.end(), -1);
      level[s] = 0;
      q.push(s);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(s, flow_inf)) {
        f += pushed;
      }
    }
    return f;
  }
};
const int inf = 9999999;
string s;
int cnt[200];
int main() {
  int t;
  cin >> t;
  while (t--) {
    map<pair<int, int>, int> mp;
    map<int, pair<int, int>> mp2;
    vector<vector<int>> vt(1000);
    vector<pair<int, int>> edges;
    int n, m, k, a, b, x = 1;
    int ans[1000] = {0};
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
      cin >> a >> b;
      vt[a].push_back(b);
      vt[b].push_back(a);
      pair<int, int> p1 = {a, b}, p2 = {b, a};
      mp[p1] = x;
      mp[p2] = x;
      mp2[x] = p1;
      x++;
      edges.push_back({a, b});
    }
    int manda = 0, chega = n + m + 1, flag = 0, sum = 0;
    Dinic d(chega + 1, manda, chega);
    for (int i = 1; i <= n; i++) {
      int tam = vt[i].size();
      if (tam > 2 * k)
        flag = 1;
      else if (k < tam && tam <= 2 * k) {
        for (int j = 0; j < vt[i].size(); j++) {
          d.add_edge(i, n + mp[make_pair(i, vt[i][j])], 1);
        }
        d.add_edge(manda, i, 2 * (tam - k));
        sum += 2 * (tam - k);
      }
    }
    for (int i = 0; i < m; i++) d.add_edge(mp[edges[i]] + n, chega, 1);
    if (flag == 1) {
      for (int i = 0; i < m; i++) cout << 0 << " ";
      cout << endl;
    } else {
      int flw = d.flow();
      if (flw == sum) {
        int y = 1, cont = 0;
        for (int i = 0; i < d.edges.size(); i += 2) {
          if (d.edges[i].v <= n && d.edges[i].v != manda &&
              d.edges[i].flow == 1) {
            ans[d.edges[i].u - n] = y;
            cont++;
            if (cont == 2) {
              y++;
              cont = 0;
            }
          }
        }
        for (int i = 1; i <= m; i++) {
          if (ans[i] == 0) {
            cout << y << " ";
            y++;
          } else {
            cout << ans[i] << " ";
          }
        }
        cout << endl;
      } else {
        for (int i = 0; i < m; i++) cout << 0 << " ";
        cout << endl;
      }
    }
  }
}