#include <bits/stdc++.h>
using namespace std;
int n, m, k, col[1010], cnt = 0, id[2010], deg[4010];
pair<int, int> ed[4010][1010];
void dfs(int u, int v, int c1, int c2, int id) {
  ed[u][c1] = make_pair(v, id), col[id] = c1;
  if (ed[v][c1].first)
    dfs(v, ed[v][c1].first, c2, c1, ed[v][c1].second);
  else
    ed[v][c2] = make_pair(0, 0);
  ed[v][c1] = make_pair(u, id);
}
void add_edge(int u, int v, int id) {
  deg[u]++, deg[v]++;
  for (int i = 1; i <= k; i++)
    if (!ed[u][i].first && !ed[v][i].first) {
      ed[u][i] = make_pair(v, id), ed[v][i] = make_pair(u, id), col[id] = i;
      return;
    }
  int c1 = -1, c2 = -1;
  for (int i = 1; i <= k; i++)
    if (!ed[u][i].first) {
      c1 = i;
      break;
    }
  for (int i = 1; i <= k; i++)
    if (!ed[v][i].first) {
      c2 = i;
      break;
    }
  assert(c1 > 0 && c2 > 0);
  dfs(u, v, c1, c2, id);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1, w; i <= n; i++) scanf("%d", &w);
  for (int i = 1; i <= 2 * n; i++) id[i] = ++cnt;
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    if (u > v) swap(u, v);
    if (deg[id[u]] == k) id[u] = ++cnt;
    if (deg[id[v + n]] == k) id[v + n] = ++cnt;
    add_edge(id[u], id[v + n], i);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", col[i]);
}
