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;
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;
  }
}