Problem: There are n football teams in the world. 

The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. 

Let s_{ij} be the numbers of games the i-th team played in the j-th stadium. MFO does not want a team to have much more games in one stadium than in the others. Therefore, for each team i, the absolute difference between the maximum and minimum among s_{i1}, s_{i2}, …, s_{ik} should not exceed 2.

Each team has w_i — the amount of money MFO will earn for each game of the i-th team. If the i-th team plays l games, MFO will earn w_i ⋅ l.

MFO needs to find what games in what stadiums they need to host in order to earn as much money as possible, not violating the rule they set.

However, this problem is too complicated for MFO. Therefore, they are asking you to help them.

Input

The first line contains three integers n, m, k (3 ≤ n ≤ 100, 0 ≤ m ≤ 1 000, 1 ≤ k ≤ 1 000) — the number of teams, the number of games, and the number of stadiums.

The second line contains n integers w_1, w_2, …, w_n (1 ≤ w_i ≤ 1 000) — the amount of money MFO will earn for each game of the i-th game.

Each of the following m lines contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) — the teams that can play the i-th game. It is guaranteed that each pair of teams can play at most one game.

Output

For each game in the same order, print t_i (1 ≤ t_i ≤ k) — the number of the stadium, in which a_i and b_i will play the game. If the i-th game should not be played, t_i should be equal to 0.

If there are multiple answers, print any.

Example

Input


7 11 3
4 7 8 10 10 9 3
6 2
6 1
7 6
4 3
4 6
3 1
5 3
7 5
7 3
4 2
1 4


Output


3
2
1
1
3
1
2
1
2
3
2

Note

One of possible solutions to the example is shown below:

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
const int MAXN = 101, MAXM = 1001;
int n, m, k, w[MAXN], a[MAXM], b[MAXM];
int color[MAXM];
set<pii> s[MAXN], s2;
int deg[MAXN][MAXM];
inline pii get_s2(int i) {
  return {s[i].begin()->first - s[i].rbegin()->first, i};
}
inline void change_edge_color(int eid, int d) {
  int p1 = a[eid], p2 = b[eid];
  s[p1].erase({deg[p1][color[eid]], color[eid]});
  s[p2].erase({deg[p2][color[eid]], color[eid]});
  deg[p1][color[eid]] += d;
  deg[p2][color[eid]] += d;
  s[p1].insert({deg[p1][color[eid]], color[eid]});
  s[p2].insert({deg[p2][color[eid]], color[eid]});
}
inline void change_color(int eid, int col) {
  if (eid == 0 || eid > m || color[eid] == col) {
    return;
  }
  int p1 = a[eid], p2 = b[eid];
  s2.erase(get_s2(p1));
  s2.erase(get_s2(p2));
  change_edge_color(eid, -1);
  color[eid] = col;
  change_edge_color(eid, 1);
  s2.insert(get_s2(p1));
  s2.insert(get_s2(p2));
}
vector<pii> v2[MAXN];
int deg2[MAXN];
vector<int> vertices;
int used[MAXN];
void dfs2(int pos) {
  used[pos] = 2;
  for (auto &adj : v2[pos]) {
    if (used[adj.first] != 2) {
      dfs2(adj.first);
    }
  }
  vertices.push_back(pos);
}
set<int> used3;
vector<int> euler;
void dfs3(int pos, int prev = -1, int pr2 = 0) {
  while (!v2[pos].empty()) {
    int idx = v2[pos].back().second;
    int to = v2[pos].back().first;
    v2[pos].pop_back();
    if (used3.find(idx) != used3.end()) {
      continue;
    }
    used3.insert(idx);
    dfs3(to, idx, pos);
  }
  if (prev != -1) {
    euler.push_back(prev);
  }
}
void stabilize_two_colors(const vector<int> &e, int col1, int col2) {
  v2[0].clear();
  for (auto &idx : e) {
    v2[a[idx]].clear();
    v2[b[idx]].clear();
    deg2[a[idx]] = 0;
    deg2[b[idx]] = 0;
    used[a[idx]] = 0;
    used[b[idx]] = 0;
  }
  for (auto &idx : e) {
    v2[a[idx]].push_back({b[idx], idx});
    v2[b[idx]].push_back({a[idx], idx});
  }
  vertices.clear();
  int u = m;
  for (auto &idx : e) {
    if (used[a[idx]] != 2) {
      int k = vertices.size();
      dfs2(a[idx]);
      bool find = false;
      for (int i = k; i < 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 (auto &idx : e) {
    deg[a[idx]][color[idx]]++;
    deg[b[idx]][color[idx]]++;
  }
  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 idx = s2.begin()->second;
    int col1 = s[idx].begin()->second;
    int col2 = s[idx].rbegin()->second;
    vector<int> e2;
    for (auto &eid : e) {
      if (color[eid] == col1 || color[eid] == col2) {
        e2.push_back(eid);
      }
    }
    stabilize_two_colors(e2, col1, col2);
  }
}
void make_random(vector<int> e) {
  random_shuffle(e.begin(), e.end());
  for (int i = 0; i < e.size(); i++) {
    color[e[i]] = i % k + 1;
  }
  stabilize(e);
}
int change[MAXN];
void build(vector<int> e) {
  if (e.size() <= n * k) {
    make_random(e);
    return;
  }
  random_shuffle(e.begin(), e.end());
  vector<int> e1, e2;
  int s = e.size() / 2;
  for (int i = 0; i < e.size(); i++) {
    if (i < s) {
      e1.push_back(e[i]);
    } else {
      e2.push_back(e[i]);
    }
  }
  build(e1);
  build(e2);
  vector<pii> v1(k), v2(k);
  for (int i = 1; i <= k; i++) {
    v1[i - 1] = {0, i};
    v2[i - 1] = {0, i};
  }
  for (auto &idx : e1) {
    v1[color[idx] - 1].first++;
  }
  for (auto &idx : e2) {
    v2[color[idx] - 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 (auto &idx : e1) {
    color[idx] = change[color[idx]];
  }
  for (int i = 0; i < k; i++) {
    change[v2[i].second] = i + 1;
  }
  for (auto &idx : e2) {
    color[idx] = change[color[idx]];
  }
  stabilize(e);
}
int main() {
  ios::sync_with_stdio(false);
  srand(time(nullptr));
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
  }
  i64 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++) {
    cout << color[i] << '\n';
  }
  return 0;
}