#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 110, maxm = 1110, maxk = 1010;
int n, m, K;
int en = 0;
int col[maxm + 5];
vector<pair<int, int> > adj[maxn + 5];
vector<pair<int, int> > cur[maxn + 5];
inline void add_edge(int first, int second) {
  adj[first].push_back(make_pair(second, en));
  adj[second].push_back(make_pair(first, en));
  ++en;
}
int cnt, col0, col1;
bool vis[maxm + 5];
void dfs(int first) {
  while (!cur[first].empty()) {
    auto u = cur[first].back();
    cur[first].pop_back();
    if (!vis[u.second]) {
      vis[u.second] = 1;
      dfs(u.first);
      col[u.second] = cnt ? col0 : col1;
      cnt ^= 1;
    }
  }
}
void work(int _col0, int _col1) {
  memset(vis, 0, sizeof vis);
  col0 = _col0;
  col1 = _col1;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    cur[i].clear();
    for (auto j : adj[i])
      if (col[j.second] == col0 || col[j.second] == col1) cur[i].push_back(j);
  }
  int tmp = en;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i)
    if ((int((cur[i]).size())) & 1) {
      cur[i].push_back(make_pair(n, tmp));
      cur[n].push_back(make_pair(i, tmp));
      ++tmp;
    }
  cnt = 0;
  for (int i = n; i >= 0; --i)
    if (!cur[i].empty()) dfs(i);
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) scanf("%*d");
  for (int i = (0), i_end_ = (m); i < i_end_; ++i) {
    int u, v;
    scanf("%d%d", &u, &v), --u, --v;
    add_edge(u, v);
  }
  memset(col, 0, sizeof col);
  while (1) {
    bool found = 0;
    for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
      while (1) {
        static int num[maxk + 5];
        memset(num, 0, sizeof num);
        for (auto j : adj[i]) ++num[col[j.second]];
        int Min = 0, Max = 0;
        for (int j = (1), j_end_ = (K); j < j_end_; ++j) {
          if (num[j] > num[Max]) Max = j;
          if (num[j] < num[Min]) Min = j;
        }
        if (num[Max] - num[Min] > 2)
          work(Min, Max), found = 1;
        else
          break;
      }
    }
    if (!found) break;
  }
  for (int i = (0), i_end_ = (m); i < i_end_; ++i) printf("%d\n", col[i] + 1);
  return 0;
}
