#include <bits/stdc++.h>
using namespace std;
auto random_address = [] {
  char *p = new char;
  delete p;
  return (uint64_t)p;
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() *
            (random_address() | 1));
const int N_MAX = 105, K_MAX = 1005;
const int INF = 1e9 + 5;
struct edge {
  int a, b, color, index;
};
int N, M, K;
vector<edge> edges;
int color_count[N_MAX][K_MAX];
void set_color(edge &e, int color) {
  color_count[e.a][e.color]--;
  color_count[e.b][e.color]--;
  e.color = color;
  color_count[e.a][e.color]++;
  color_count[e.b][e.color]++;
}
bool fix(int node) {
  int minimum = INF, maximum = 0;
  for (int k = 0; k < K; k++) {
    minimum = min(minimum, color_count[node][k]);
    maximum = max(maximum, color_count[node][k]);
  }
  if (maximum - minimum <= 2) return false;
  for (edge &e : edges)
    if ((e.a == node || e.b == node) && color_count[node][e.color] == maximum) {
      set_color(e, rng() % K);
      return true;
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> M >> K;
  for (int i = 0; i < N; i++) {
    int _;
    cin >> _;
  }
  edges.resize(M);
  for (int i = 0; i < M; i++) {
    edge &e = edges[i];
    e.index = i;
    cin >> e.a >> e.b;
    e.a--;
    e.b--;
    if (e.a > e.b) swap(e.a, e.b);
    e.color = rng() % K;
    color_count[e.a][e.color]++;
    color_count[e.b][e.color]++;
  }
  vector<int> order(N);
  for (int i = 0; i < N; i++) order[i] = i;
  while (true) {
    shuffle(edges.begin(), edges.end(), rng);
    shuffle(order.begin(), order.end(), rng);
    bool any = false;
    for (int x : order)
      while (fix(x)) any = true;
    if (!any) {
      vector<int> answers(M);
      for (edge &e : edges) answers[e.index] = e.color + 1;
      for (int i = 0; i < M; i++) cout << answers[i] << '\n';
      return 0;
    }
  }
}
