#include <bits/stdc++.h>
using namespace std;
int n, m, K, w;
int nxt[5005][1005], deg[1005], ed[1005][1005], col[1005], id[1005];
void dfs(int id, int a, int b) {
  swap(ed[id][b], ed[id][a]);
  swap(nxt[id][b], nxt[id][a]);
  col[ed[id][b]] = b;
  if (nxt[id][b]) dfs(nxt[id][b], b, a);
}
int main() {
  scanf("%d %d %d", &n, &m, &K);
  int x, y, p1, p2, T = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &x);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    y += n;
    p1 = p2 = 0;
    if (deg[x] % K == 0) id[x] = ++T;
    deg[x]++;
    x = id[x];
    if (deg[y] % K == 0) id[y] = ++T;
    deg[y]++;
    y = id[y];
    for (int j = 1; j <= K; j++)
      if (!nxt[x][j] && !nxt[y][j]) p1 = j, j = K + 1;
    if (!p1) {
      for (int j = 1; j <= K; j++)
        if (!nxt[x][j]) p1 = j, j = K + 1;
      for (int j = 1; j <= K; j++)
        if (!nxt[y][j]) p2 = j, j = K + 1;
      dfs(y, p1, p2);
    }
    nxt[x][p1] = y, nxt[y][p1] = x, ed[x][p1] = i, ed[y][p1] = i, col[i] = p1;
  }
  for (int i = 1; i <= m; i++) printf("%d\n", col[i]);
}
