#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int value[N];
vector<int> g[N];
int lvl[N];
vector<pair<int, int>> nodes;
int L[N], R[N];
void dfs(int node, int par) {
  lvl[node] = lvl[par] + 1;
  L[node] = nodes.size();
  nodes.emplace_back(lvl[node], value[node]);
  for (auto u : g[node])
    if (u != par) dfs(u, node);
  R[node] = nodes.size() - 1;
}
vector<pair<int, int>> tree[N << 2];
void build(int i, int l, int r) {
  if (l == r) return void(tree[i].emplace_back(nodes[l]));
  int mid = l + r >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  merge(tree[i << 1].begin(), tree[i << 1].end(), tree[i << 1 | 1].begin(),
        tree[i << 1 | 1].end(), back_inserter(tree[i]));
  for (int j = 1; j < tree[i].size(); j++)
    tree[i][j].second = min(tree[i][j].second, tree[i][j - 1].second);
}
int get(int i, int l, int r, int a, int b, int max_depth) {
  if (l > b || r < a) return 2e9;
  if (l >= a && r <= b) {
    auto it = upper_bound(tree[i].begin(), tree[i].end(),
                          make_pair(max_depth, (int)2e9));
    if (it == tree[i].begin()) return 2e9;
    --it;
    return it->second;
  }
  int mid = l + r >> 1;
  return min(get(i << 1, l, mid, a, b, max_depth),
             get(i << 1 | 1, mid + 1, r, a, b, max_depth));
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, root;
  cin >> n >> root;
  for (int i = 1; i <= n; i++) cin >> value[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(root, root);
  build(1, 0, n - 1);
  int m;
  cin >> m;
  int last = 0;
  while (m--) {
    int p, q;
    cin >> p >> q;
    int x, k;
    x = (p + last) % n + 1;
    k = (q + last) % n;
    cout << (last = get(1, 0, n - 1, L[x], R[x], lvl[x] + k)) << '\n';
  }
  return 0;
}
