#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<int, int>;
vector<pii> adj[1010];
int col[1010], flag[1010];
int cnt[1010][1010];
int ed[1010];
int n, m, k;
int runs = 0;
int main() {
  cin >> n >> m >> k;
  for (int i = 1, u; i <= n; i++) {
    scanf("%d", &u);
  }
  for (int i = 1; i <= m; i++) {
    int u, v, A = 1, B = 1;
    scanf("%d %d", &u, &v);
    for (int j = 1; j <= k; j++) {
      if (cnt[u][A] > cnt[u][j]) A = j;
      if (cnt[v][B] > cnt[v][j]) B = j;
    }
    if (cnt[v][A] <= cnt[v][B] + 1) {
      col[i] = A;
      cnt[u][A]++;
      cnt[v][A]++;
      adj[u].push_back({v, i});
      adj[v].push_back({u, i});
      continue;
    }
    if (cnt[u][B] > cnt[u][A] + 1) {
      int p = u, c = B;
      runs++;
      while (1) {
        int f = 1;
        ed[p] = adj[p].size() - 1;
        for (; ed[p] >= 0; ed[p]--) {
          int x = adj[p][ed[p]].second;
          if (flag[x] == runs || col[x] != c) continue;
          flag[x] = runs;
          cnt[p][c]--;
          cnt[p][c ^ A ^ B]++;
          p = adj[p][ed[p]].first;
          cnt[p][c]--;
          cnt[p][c ^ A ^ B]++;
          f = 0;
          col[x] = c ^= A ^ B;
          break;
        }
        if (f) break;
      }
    }
    col[i] = B;
    cnt[u][B]++;
    cnt[v][B]++;
    adj[u].push_back({v, i});
    adj[v].push_back({u, i});
  }
  for (int i = 1; i <= m; i++) printf("%d\n", col[i]);
  return 0;
}
