#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 1005;
int n, m, K;
int col[M];
int deg[N][M];
vector<pair<int, int> > edges;
vector<pair<int, int> > G[N];
vector<int> tour;
bool vis[M + N * 2];
void dfs(int p) {
  while (!G[p].empty()) {
    int v = G[p].back().first;
    int id = G[p].back().second;
    G[p].pop_back();
    if (!vis[id]) {
      vis[id] = true;
      dfs(v);
      tour.push_back(id);
    }
  }
}
void adjust(int a, int b) {
  for (int i = 0; i < m; i++) {
    if (col[i] == a || col[i] == b) {
      int u = edges[i].first, v = edges[i].second;
      G[u].emplace_back(v, i);
      G[v].emplace_back(u, i);
      --deg[u][col[i]];
      --deg[v][col[i]];
    }
  }
  int cnt = m;
  for (int i = 1; i <= n; i++) {
    G[0].emplace_back(i, cnt);
    G[i].emplace_back(0, cnt++);
    if (G[i].size() & 1) {
      G[0].emplace_back(i, cnt);
      G[i].emplace_back(0, cnt++);
    }
  }
  dfs(0);
  int cur = b;
  for (auto id : tour) {
    if (id < m) {
      int u = edges[id].first, v = edges[id].second;
      col[id] = (cur ^= a ^ b);
      ++deg[u][col[id]];
      ++deg[v][col[id]];
    }
    vis[id] = false;
  }
  tour.clear();
}
int main() {
  srand((unsigned)time(NULL));
  scanf("%d%d%d", &n, &m, &K);
  for (int i = 1; i <= n; i++) scanf("%*d");
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    edges.emplace_back(u, v);
    col[i] = rand() % K + 1;
    ++deg[u][col[i]];
    ++deg[v][col[i]];
  }
loop:
  for (int i = 1; i <= n; i++) {
    int *pmx = deg[i] + 1, *pmi = deg[i] + 1;
    for (int *p = deg[i] + 2, *_ = deg[i] + K + 1; p != _; p++) {
      if (*p > *pmx) pmx = p;
      if (*p < *pmi) pmi = p;
    }
    if (*pmx - *pmi > 2) {
      adjust(pmx - deg[i], pmi - deg[i]);
      goto loop;
    }
  }
  for (int i = 0; i < m; i++) printf("%d\n", col[i]);
  return 0;
}
