#include <bits/stdc++.h>
const int N = 1005;
int to[N << 1][N], id[N], n, m, k, c[N], x, y, col[N], eid[N << 1][N], cnt;
void dfs(int x, int cx, int cy) {
  if (to[x][cx]) dfs(to[x][cx], cy, cx);
  std::swap(to[x][cx], to[x][cy]);
  std::swap(eid[x][cx], eid[x][cy]);
  col[eid[x][cy]] = cy;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &x);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    y += n;
    if (!c[x]) id[x] = ++cnt;
    if (!c[y]) id[y] = ++cnt;
    c[x]++, c[y]++, c[x] %= k, c[y] %= k;
    x = id[x], y = id[y];
    int cx = 0, cy = 0;
    for (int j = 1; j <= k; j++) {
      if (!to[x][j]) cx = j;
      if (!to[y][j]) cy = j;
    }
    if (cx != cy) dfs(y, cx, cy);
    to[x][cx] = y, to[y][cx] = x;
    eid[x][cx] = i, eid[y][cx] = i;
    col[i] = cx;
  }
  for (int i = 1; i <= m; i++) printf("%d\n", col[i]);
}
