#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 101;
const int MAX_M = 1001;
int n, m, k;
vector<pair<int, int> > v[MAX_N];
int w[MAX_N];
int a[MAX_M], b[MAX_M], c[MAX_M], color[MAX_M];
set<pair<int, int> > s[MAX_N], s2;
int deg[MAX_N][MAX_M];
inline pair<int, int> get_s2(int i) {
  return {s[i].begin()->first - s[i].rbegin()->first, i};
}
inline void change_edge_color(int edge, int d) {
  int pos1 = a[edge];
  int pos2 = b[edge];
  assert(s[pos1].find({deg[pos1][color[edge]], color[edge]}) != s[pos1].end());
  s[pos1].erase({deg[pos1][color[edge]], color[edge]});
  s[pos2].erase({deg[pos2][color[edge]], color[edge]});
  deg[pos1][color[edge]] += d;
  deg[pos2][color[edge]] += d;
  s[pos1].insert({deg[pos1][color[edge]], color[edge]});
  s[pos2].insert({deg[pos2][color[edge]], color[edge]});
}
inline void change_color(int edge, int col) {
  if (edge == 0 || edge > m || color[edge] == col) return;
  int pos1 = a[edge];
  int pos2 = b[edge];
  s2.erase(get_s2(pos1));
  s2.erase(get_s2(pos2));
  change_edge_color(edge, -1);
  color[edge] = col;
  change_edge_color(edge, 1);
  s2.insert(get_s2(pos1));
  s2.insert(get_s2(pos2));
}
vector<pair<int, int> > v2[MAX_N];
int deg2[MAX_N];
vector<int> vertices;
int used[MAX_N];
void dfs2(int pos) {
  used[pos] = 2;
  for (auto e : v2[pos]) {
    if (used[e.first] != 2) {
      dfs2(e.first);
    }
  }
  vertices.push_back(pos);
}
int _col[2];
set<int> used3;
int i;
vector<int> euler;
void dfs3(int pos, int prev = -1, int pr2 = 0) {
  while (!v2[pos].empty()) {
    int ind = v2[pos].back().second;
    int to = v2[pos].back().first;
    v2[pos].pop_back();
    if (used3.find(ind) != used3.end()) {
      continue;
    }
    used3.insert(ind);
    dfs3(to, ind, pos);
  }
  if (prev != -1) {
    euler.push_back(prev);
  }
}
void stabilize_two_colors(const vector<int> &e, int col1, int col2) {
  assert(!e.empty());
  v2[0].clear();
  for (auto edge : e) {
    v2[a[edge]].clear();
    v2[b[edge]].clear();
    deg2[a[edge]] = 0;
    deg2[b[edge]] = 0;
    used[a[edge]] = 0;
    used[b[edge]] = 0;
  }
  for (auto edge : e) {
    v2[a[edge]].push_back({b[edge], edge});
    v2[b[edge]].push_back({a[edge], edge});
  }
  vertices.clear();
  int u = m;
  for (auto edge : e) {
    if (used[a[edge]] != 2) {
      int k = (int)vertices.size();
      dfs2(a[edge]);
      bool find = false;
      for (int i = k; i < (int)vertices.size(); i++) {
        int v = vertices[i];
        if (v2[v].size() % 2 == 1) {
          find = true;
          ++u;
          v2[v].push_back({0, u});
          v2[0].push_back({v, u});
        }
      }
      if (!find) {
        int v = vertices[k];
        for (int j = 0; j < 2; j++) {
          ++u;
          v2[v].push_back({0, u});
          v2[0].push_back({v, u});
        }
      }
    }
  }
  used3.clear();
  euler.clear();
  dfs3(0);
  for (int a : euler) {
    change_color(a, col1);
    swap(col1, col2);
  }
}
void stabilize(const vector<int> &e) {
  s2.clear();
  for (int i = 1; i <= n; i++) {
    s[i].clear();
    for (int j = 1; j <= k; j++) {
      deg[i][j] = 0;
    }
  }
  for (int edge : e) {
    deg[a[edge]][color[edge]]++;
    deg[b[edge]][color[edge]]++;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      s[i].insert({deg[i][j], j});
    }
    s2.insert(get_s2(i));
  }
  while (-s2.begin()->first > 2) {
    int ind = s2.begin()->second;
    int col1 = s[ind].begin()->second;
    int col2 = s[ind].rbegin()->second;
    vector<int> e2;
    for (int edge : e) {
      if (color[edge] == col1 || color[edge] == col2) {
        e2.push_back(edge);
      }
    }
    stabilize_two_colors(e2, col1, col2);
  }
}
void make_random(vector<int> e) {
  random_shuffle(e.begin(), e.end());
  for (int i = 0; i < (int)e.size(); i++) {
    color[e[i]] = i % k + 1;
  }
  stabilize(e);
}
int change[MAX_N];
void build(vector<int> e) {
  if ((int)e.size() <= n * k) {
    make_random(e);
    return;
  }
  random_shuffle(e.begin(), e.end());
  vector<int> e1, e2;
  int s = (int)e.size() / 2;
  for (int i = 0; i < (int)e.size(); i++) {
    if (i < s) {
      e1.push_back(e[i]);
    } else {
      e2.push_back(e[i]);
    }
  }
  build(e1);
  build(e2);
  vector<pair<int, int> > v1(k), v2(k);
  for (int i = 1; i <= k; i++) {
    v1[i - 1].first = v2[i - 1].first = 0;
    v1[i - 1].second = v2[i - 1].second = i;
  }
  for (int edge : e1) {
    v1[color[edge] - 1].first++;
  }
  for (int edge : e2) {
    v2[color[edge] - 1].first++;
  }
  sort(v1.rbegin(), v1.rend());
  sort(v2.begin(), v2.end());
  for (int i = 0; i < k; i++) {
    change[v1[i].second] = i + 1;
  }
  for (int edge : e1) {
    color[edge] = change[color[edge]];
  }
  for (int i = 0; i < k; i++) {
    change[v2[i].second] = i + 1;
  }
  for (int edge : e2) {
    color[edge] = change[color[edge]];
  }
  stabilize(e);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(NULL));
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
  }
  long long sum = 0;
  vector<int> e;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    sum += w[a[i]] + w[b[i]];
    e.push_back(i);
  }
  build(e);
  for (int i = 1; i <= m; i++) {
    assert(color[i]);
    cout << color[i] << endl;
  }
}
