#include <bits/stdc++.h>
using namespace std;
const int maxn = 1079;
int n, m, k;
vector<int> col(maxn), path, vis;
vector<vector<pair<int, int> > > g(maxn);
vector<int> getf(int v) {
  vector<int> f(k, 0);
  for (pair<int, int> i : g[v]) f[col[i.second]]++;
  int mini = *min_element(f.begin(), f.end());
  for (int i = 0; i < k; i++) f[i] -= mini;
  return f;
}
void dfs(int v, int a, int b) {
  for (pair<int, int> i : g[v]) {
    if (vis[i.second] || col[i.second] != a) continue;
    vis[i.second] = true, path.push_back(i.second);
    dfs(i.first, b, a);
    return;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 0, tmp; i < n; i++) cin >> tmp;
  for (int i = 0, u, v; i < m; i++) {
    cin >> u >> v;
    u--, v--;
    vector<int> fu = getf(u), fv = getf(v);
    int c = -1, a, b;
    for (int j = 0; j < k; j++) {
      if (fu[j] != 2 && fv[j] != 2) {
        c = j;
        break;
      }
      if (fu[j] == 0) a = j;
      if (fv[j] == 0) b = j;
    }
    if (c == -1) {
      path.clear(), vis.assign(m, 0);
      dfs(v, a, b);
      for (int i : path) col[i] ^= a ^ b;
      col[i] = a;
    } else
      col[i] = c;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  for (int i = 0; i < m; i++) cout << col[i] + 1 << "\n";
  return 0;
}
