#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long qpow(long long a, long long b) {
  long long res = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) res = res * a % mod;
  return res;
}
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 50;
vector<int> to[maxn];
int a[maxn], dep[maxn], l[maxn], r[maxn], id[maxn], cc;
void dfs(int pos, int fa) {
  l[pos] = ++cc;
  id[cc] = pos;
  for (int v : to[pos])
    if (v != fa) {
      dep[v] = dep[pos] + 1;
      dfs(v, pos);
    }
  r[pos] = cc;
}
vector<pair<int, int> > has[maxn << 2];
void build(int rt, int l, int r) {
  has[rt].resize(r - l + 1);
  for (int i = l; i <= r; ++i) {
    has[rt][i - l] = pair<int, int>(dep[id[i]], a[id[i]]);
  }
  sort(has[rt].begin(), has[rt].end());
  for (int i = 1; i < has[rt].size(); ++i)
    has[rt][i].second = min(has[rt][i].second, has[rt][i - 1].second);
  if (l != r) {
    int mid = (l + r) >> 1;
    build((rt << 1), l, mid);
    build((rt << 1 | 1), mid + 1, r);
  }
}
int query(int rt, int l, int r, int L, int R, int d) {
  if (L <= l and r <= R) {
    if (has[rt][0].first > d) return inf;
    int pos =
        lower_bound(has[rt].begin(), has[rt].end(), pair<int, int>(d + 1, -1)) -
        has[rt].begin() - 1;
    return has[rt][pos].second;
  } else {
    int mid = (l + r) >> 1;
    int res = inf;
    if (L <= mid) res = min(res, query((rt << 1), l, mid, L, R, d));
    if (R > mid) res = min(res, query((rt << 1 | 1), mid + 1, r, L, R, d));
    return res;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, rt;
  cin >> n >> rt;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    to[u].push_back(v);
    to[v].push_back(u);
  }
  dep[rt] = 1;
  dfs(rt, 0);
  build(1, 1, n);
  int q;
  cin >> q;
  int la = 0;
  while (q--) {
    int x, k;
    cin >> x >> k;
    x = (x + la) % n + 1, k = (k + la) % n;
    la = query(1, 1, n, l[x], r[x], dep[x] + k);
    cout << la << "\n";
  }
  return 0;
}
