#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100;
const int MAXM = 1000;
const int MAXCOL = 1000;
int n, m, ncol;
int w[MAXN];
int e[MAXM][2];
int ans[MAXM];
vector<int> adj[MAXN];
vector<int> getadjcol(int at) {
  vector<int> ret(ncol, 0);
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int id = adj[at][i];
    ++ret[ans[id]];
  }
  return ret;
}
void recolor(int at, int x, int y) {
  vector<int> posx(n, 0), posy(n, 0);
  vector<bool> used(m, false);
  while (true) {
    if (posx[at] >= ((int)(adj[at]).size())) break;
    int id = adj[at][posx[at]++];
    if (used[id]) continue;
    if (ans[id] != x) continue;
    used[id] = true, ans[id] = y, swap(x, y), swap(posx, posy),
    at = e[id][0] ^ e[id][1] ^ at;
  }
}
void solve() {
  for (int i = (0); i < (n); ++i) adj[i].clear();
  for (int i = (0); i < (m); ++i) {
    int a = e[i][0], b = e[i][1];
    vector<int> acnt = getadjcol(a);
    vector<int> bcnt = getadjcol(b);
    int amn = 0;
    for (int j = (1); j < (ncol); ++j)
      if (acnt[j] < acnt[amn]) amn = j;
    int bmn = 0;
    for (int j = (1); j < (ncol); ++j)
      if (bcnt[j] < bcnt[bmn]) bmn = j;
    if (bcnt[amn] >= bcnt[bmn] + 2) {
      assert(amn != bmn);
      recolor(b, amn, bmn);
    }
    ans[i] = amn;
    adj[a].push_back(i), adj[b].push_back(i);
  }
}
void run() {
  scanf("%d%d%d", &n, &m, &ncol);
  for (int i = (0); i < (n); ++i) scanf("%d", &w[i]);
  for (int i = (0); i < (m); ++i)
    for (int j = (0); j < (2); ++j) scanf("%d", &e[i][j]), --e[i][j];
  solve();
  for (int i = (0); i < (m); ++i) printf("%d\n", ans[i] + 1);
}
int main() {
  run();
  return 0;
}
