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 INFINI = 1000 * 1000 * 1000;
struct Graph {
  int source, puits;
  vector<pair<int, int>> arcs;
  vector<vector<pair<int, int>>> voisins;
  int curPasse;
  vector<int> derPasse;
  vector<int> dists;
  int new_node() {
    voisins.push_back(vector<pair<int, int>>());
    derPasse.push_back(0);
    return voisins.size() - 1;
  }
  Graph() {
    source = new_node();
    puits = new_node();
    curPasse = 1;
  }
  int new_directed_edge(int deb, int fin, int cap) {
    int id = arcs.size();
    int r_id = id + 1;
    arcs.push_back({cap, r_id});
    arcs.push_back({0, id});
    voisins[deb].push_back({fin, id});
    voisins[fin].push_back({deb, r_id});
    return id;
  }
  int new_edge(int deb, int fin, int cap) {
    int id = arcs.size();
    int r_id = id + 1;
    arcs.push_back({cap, r_id});
    arcs.push_back({cap, id});
    voisins[deb].push_back({fin, id});
    voisins[fin].push_back({deb, r_id});
    return id;
  }
  void reset_dists() { dists = vector<int>(voisins.size(), INFINI); }
  void bfs() {
    reset_dists();
    list<pair<int, int>> noeuds;
    noeuds.push_back({source, 0});
    while (!noeuds.empty()) {
      pair<int, int> noeud = noeuds.front();
      noeuds.pop_front();
      if (derPasse[noeud.first] == curPasse) continue;
      derPasse[noeud.first] = curPasse;
      dists[noeud.first] = noeud.second;
      for (pair<int, int> voisin : voisins[noeud.first]) {
        if (arcs[voisin.second].first != 0) {
          noeuds.push_back({voisin.first, noeud.second + 1});
        }
      }
    }
  }
  int ameliore(int noeud, int flot = INFINI) {
    if (derPasse[noeud] == curPasse) return 0;
    derPasse[noeud] = curPasse;
    if (noeud == puits) {
      return flot;
    }
    for (pair<int, int> voisin : voisins[noeud]) {
      if (arcs[voisin.second].first != 0 &&
          dists[voisin.first] == dists[noeud] + 1) {
        int ajout =
            ameliore(voisin.first, min(flot, arcs[voisin.second].first));
        if (ajout != 0) {
          arcs[voisin.second].first -= ajout;
          arcs[arcs[voisin.second].second].first += ajout;
          return ajout;
        }
      }
    }
    return 0;
  }
  int flot() {
    int reponse = 0;
    while (true) {
      curPasse++;
      bfs();
      if (dists[puits] == INFINI) break;
      while (true) {
        curPasse++;
        int ajout = ameliore(source);
        if (ajout == 0) break;
        reponse += ajout;
      }
    }
    return reponse;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  int nbTests;
  cin >> nbTests;
  for (int iTest = 0; iTest < nbTests; iTest++) {
    int nbVilles, nbRoutes, maxDiff;
    cin >> nbVilles >> nbRoutes >> maxDiff;
    Graph g;
    vector<int> deg(nbVilles, 0);
    vector<int> ids_villes;
    for (int iVille = 0; iVille < nbVilles; iVille++) {
      ids_villes.push_back(g.new_node());
    }
    vector<vector<pair<int, int>>> arcs(nbVilles);
    vector<int> reponses(nbRoutes, 0);
    int needed_flow = 0;
    for (int iRoute = 0; iRoute < nbRoutes; iRoute++) {
      int deb, fin;
      cin >> deb >> fin;
      deb--;
      fin--;
      int node = g.new_node();
      g.new_directed_edge(node, g.puits, 1);
      int arcDeb = g.new_directed_edge(ids_villes[deb], node, 1);
      int arcFin = g.new_directed_edge(ids_villes[fin], node, 1);
      arcs[deb].push_back({arcDeb, iRoute});
      arcs[fin].push_back({arcFin, iRoute});
      deg[deb]++;
      deg[fin]++;
      if (deg[deb] > maxDiff) {
        g.new_directed_edge(g.source, ids_villes[deb], 2);
        needed_flow += 2;
        deg[deb]--;
      }
      if (deg[fin] > maxDiff) {
        g.new_directed_edge(g.source, ids_villes[fin], 2);
        needed_flow += 2;
        deg[fin]--;
      }
    }
    if (g.flot() != needed_flow) {
      for (int iRoute = 0; iRoute < nbRoutes; iRoute++) {
        cout << 0 << " ";
      }
    } else {
      int nbCompanies = 1;
      for (int iVille = 0; iVille < nbVilles; iVille++) {
        int mod = 0;
        for (pair<int, int> arc : arcs[iVille]) {
          if (g.arcs[arc.first].first == 0) {
            reponses[arc.second] = nbCompanies;
            mod++;
            if (mod % 2 == 0) {
              nbCompanies++;
            }
          }
        }
      }
      for (int iRoute = 0; iRoute < nbRoutes; iRoute++) {
        if (reponses[iRoute] == 0) {
          reponses[iRoute] = nbCompanies++;
        }
        cout << reponses[iRoute] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}