#include <bits/stdc++.h>
inline long long read() {
  long long x = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || '9' < c; c = getchar())
    if (c == '-') f = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
inline void write(long long x) {
  static char buf[20];
  int len = 0;
  if (x < 0) putchar('-'), x = -x;
  for (; x; x /= 10) buf[len++] = x % 10 + '0';
  if (!len)
    putchar('0');
  else
    while (len) putchar(buf[--len]);
}
inline void writesp(long long x) {
  write(x);
  putchar(' ');
}
inline void writeln(long long x) {
  write(x);
  putchar('\n');
}
int deg[3010], to[3010][1010], id[3010][1010];
int col[1010];
int w[110], cur1[110], cur2[110];
int n, m, k, cnt;
void adjust(int x, int c1, int c2) {
  while (x) {
    col[id[x][c1]] = c2;
    std::swap(to[x][c1], to[x][c2]);
    std::swap(id[x][c1], id[x][c2]);
    x = to[x][c2];
    std::swap(c1, c2);
  }
}
int main() {
  n = read();
  m = read();
  k = read();
  for (int i = 1; i <= n; i++) w[i] = read();
  deg[0] = k;
  cnt = 0;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    if (deg[cur1[x]] == k) cur1[x] = ++cnt, deg[cur1[x]] = 0;
    if (deg[cur2[y]] == k) cur2[y] = ++cnt, deg[cur2[y]] = 0;
    ++deg[cur1[x]];
    ++deg[cur2[y]];
    int cx = 0, cy = 0;
    for (int j = 1; j <= k; j++)
      if (!to[cur1[x]][j]) {
        cx = j;
        break;
      }
    if (to[cur2[y]][cx]) {
      for (int j = 1; j <= k; j++)
        if (!to[cur2[y]][j]) {
          cy = j;
          break;
        }
      adjust(cur2[y], cx, cy);
    }
    to[cur1[x]][cx] = cur2[y];
    id[cur1[x]][cx] = i;
    to[cur2[y]][cx] = cur1[x];
    id[cur2[y]][cx] = i;
    col[i] = cx;
  }
  for (int i = 1; i <= m; i++) writeln(col[i]);
  return 0;
}
