#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;
      }
    }
  }
}
