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 cat = long long;
struct edge {
  int u, v, id;
};
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> W(N), D(N, 0);
  for (int i = 0; i < N; i++) cin >> W[i];
  vector<edge> E(M);
  for (int i = 0; i < M; i++) {
    cin >> E[i].u >> E[i].v;
    D[--E[i].u]++;
    D[--E[i].v]++;
    E[i].id = i;
  }
  vector<edge> E0 = E;
  int M0 = M;
  vector<edge> E_final;
  while (true) {
    bool stop = true;
    for (int i = 0; i < M; i++)
      if (min(D[E[i].u], D[E[i].v]) <= 2) {
        D[E[i].u]--;
        D[E[i].v]--;
        E_final.push_back(E[i]);
        swap(E.back(), E[i]);
        E.pop_back();
        M--;
        stop = false;
        break;
      }
    for (int i = 0; i < M; i++)
      if ((D[E[i].u] - 1) / 2 + (D[E[i].v] - 1) / 2 < K) {
        D[E[i].u]--;
        D[E[i].v]--;
        E_final.push_back(E[i]);
        swap(E.back(), E[i]);
        E.pop_back();
        M--;
        stop = false;
        break;
      }
    if (stop) break;
  }
  reverse(begin(E_final), end(E_final));
  vector<vector<int> > S_final(N, vector<int>(K, 0));
  vector<int> ans_id(M0, 0);
  int ans = 0;
  if (M > 0) {
    vector<vector<int> > seqs(10000, vector<int>(K));
    for (int i = 0; i < 10000; i++)
      for (int j = 0; j < K; j++) {
        seqs[i][j] = j;
        swap(seqs[i][j], seqs[i][rand() % (j + 1)]);
      }
    for (int r = 0; r < 50; r++) {
      srand(r);
      for (int i = 0; i < M; i++) swap(E[rand() % (i + 1)], E[i]);
      vector<char> used(M, 0);
      vector<vector<int> > S(N, vector<int>(K, 0)), S_cnt(N, vector<int>(3, 0));
      vector<int> S_min(N, 0);
      for (int i = 0; i < N; i++) S_cnt[i][0] = K;
      int cur = 0;
      vector<int> cur_id(M0, 0);
      for (int r2 = 0; r2 < (400 / K); r2++) {
        auto cur_old = cur;
        auto used_old = used;
        auto cur_id_old = cur_id;
        auto S_min_old = S_min;
        auto S_old = S;
        auto S_cnt_old = S_cnt;
        for (int i = 0; i < M; i++)
          if (used[i] && rand() % 4 == 0) {
            int s = cur_id[E[i].id] - 1, u = E[i].u, v = E[i].v;
            if (S[u][s] == S_min[u] && S_cnt[u][2]) continue;
            if (S[v][s] == S_min[v] && S_cnt[v][2]) continue;
            cur_id[E[i].id] = 0;
            S_cnt[u][S[u][s] - S_min[u]]--;
            S_cnt[v][S[v][s] - S_min[v]]--;
            if (S[u][s] == S_min[u]) {
              S_cnt[u][2] = S_cnt[u][1];
              S_cnt[u][1] = S_cnt[u][0];
              S_cnt[u][0] = 0;
              S_min[u]--;
            }
            if (S[v][s] == S_min[v]) {
              S_cnt[v][2] = S_cnt[v][1];
              S_cnt[v][1] = S_cnt[v][0];
              S_cnt[v][0] = 0;
              S_min[v]--;
            }
            S[u][s]--;
            S[v][s]--;
            S_cnt[u][S[u][s] - S_min[u]]++;
            S_cnt[v][S[v][s] - S_min[v]]++;
            cur -= W[u] + W[v];
            used[i] = 0;
          }
        for (int i = 0; i < M; i++)
          if (!used[i]) {
            int seq_id = rand() % 10000, u = E[i].u, v = E[i].v;
            int s = -1;
            for (int j = 0; j < K; j++) {
              int cur_s = seqs[seq_id][j];
              if (S[u][cur_s] == 2 + S_min[u]) continue;
              if (S[v][cur_s] == 2 + S_min[v]) continue;
              s = cur_s;
              break;
            }
            if (s == -1) continue;
            cur_id[E[i].id] = s + 1;
            S_cnt[u][S[u][s] - S_min[u]]--;
            S_cnt[v][S[v][s] - S_min[v]]--;
            if (S_cnt[u][0] == 0) {
              S_cnt[u][0] = S_cnt[u][1];
              S_cnt[u][1] = S_cnt[u][2];
              S_cnt[u][2] = 0;
              S_min[u]++;
            }
            if (S_cnt[v][0] == 0) {
              S_cnt[v][0] = S_cnt[v][1];
              S_cnt[v][1] = S_cnt[v][2];
              S_cnt[v][2] = 0;
              S_min[v]++;
            }
            S[u][s]++;
            S[v][s]++;
            S_cnt[u][S[u][s] - S_min[u]]++;
            S_cnt[v][S[v][s] - S_min[v]]++;
            cur += W[u] + W[v];
            used[i] = 1;
          }
        if (cur < cur_old) {
          cur = cur_old;
          used = used_old;
          cur_id = cur_id_old;
          S_min = S_min_old;
          S = S_old;
          S_cnt = S_cnt_old;
        }
      }
      if (cur > ans) {
        ans = cur;
        ans_id = cur_id;
        S_final = S;
      }
    }
  }
  for (auto e : E_final) {
    int min_u = 1000000, min_v = 1000000;
    for (int i = 0; i < K; i++) min_u = min(min_u, S_final[e.u][i]);
    for (int i = 0; i < K; i++) min_v = min(min_v, S_final[e.v][i]);
    for (int i = 0; i < K; i++)
      if (S_final[e.u][i] + 1 <= min_u + 2 &&
          S_final[e.v][i] + 1 <= min_v + 2) {
        S_final[e.u][i]++;
        S_final[e.v][i]++;
        ans_id[e.id] = i + 1;
        ans += W[e.u] + W[e.v];
        break;
      }
  }
  cerr << ans << "\n";
  for (int i = 0; i < M0; i++) cout << ans_id[i] << "\n";
  return 0;
}