#include <bits/stdc++.h>
using namespace std;
const int _ = 1e2;
const int maxn = 110;
const int maxm = 1100;
vector<pair<int, int> > vec[1100000];
int id, cur[maxn << 1], du[maxn << 1], col[maxm];
void solve(int x, int c1, int c2) {
  col[vec[x][c1].second] = c2;
  swap(vec[x][c1], vec[x][c2]);
  if (vec[x][c2].first) solve(vec[x][c2].first, c2, c1);
}
int main() {
  int n, m, K, ww, x, y, c1, c2;
  scanf("%d%d%d", &n, &m, &K);
  for (int i = 1; i <= n; i++) scanf("%d", &ww);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    y += n;
    if (du[x] % K == 0) cur[x] = ++id, vec[cur[x]].resize(K);
    if (du[y] % K == 0) cur[y] = ++id, vec[cur[y]].resize(K);
    du[x]++, x = cur[x];
    du[y]++, y = cur[y];
    for (int j = 0; j < K; j++)
      if (!vec[x][j].first) {
        c1 = j;
        break;
      }
    if (vec[y][c1].first) {
      for (int j = 0; j < K; j++)
        if (!vec[y][j].first) {
          c2 = j;
          break;
        }
      solve(y, c1, c2);
    }
    vec[x][c1] = make_pair(y, i);
    vec[y][c1] = make_pair(x, i);
    col[i] = c1;
  }
  for (int i = 1; i <= m; i++) printf("%d ", col[i] + 1);
  return 0;
}
