#include <bits/stdc++.h>
using namespace std;
int nA, nB, m, k, ans, x, y, c1, c2, cnt;
int deg[1310 << 1], be[190010], w[1310], w2[1310];
int id[10005][1310], f[10005][1310];
void rv(int x, int c1, int c2) {
  swap(f[x][c1], f[x][c2]);
  swap(id[x][c1], id[x][c2]);
  be[id[x][c2]] = c2;
  if (f[x][c2]) rv(f[x][c2], c2, c1);
}
int main() {
  scanf("%d%d%d", &nA, &m, &k);
  nB = nA;
  int foo;
  for (int i = 1; i <= nA; i++) scanf("%d", &foo);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    if (x < y) swap(x, y);
    if (deg[x] % k == 0) w[x] = ++cnt;
    if (deg[nA + y] % k == 0) w2[y] = ++cnt;
    deg[x]++, deg[nA + y]++;
    x = w[x], y = w2[y];
    c1 = 0, c2 = 0;
    for (int j = 1; j <= k; ++j)
      if (!f[x][j]) {
        c1 = j;
        break;
      }
    for (int j = 1; j <= k; ++j)
      if (!f[y][j]) {
        c2 = j;
        break;
      }
    if (f[y][c1]) rv(y, c1, c2);
    f[x][c1] = y;
    id[x][c1] = i;
    f[y][c1] = x;
    id[y][c1] = i;
    be[i] = c1;
  }
  for (int i = 1; i <= m; ++i) printf("%d ", be[i]);
  putchar('\n');
  return 0;
}
