#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
template <typename T>
vector<T> &operator<<(vector<T> &__container, T x) {
  __container.push_back(x);
  return __container;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &__container) {
  for (T _ : __container) out << _ << ' ';
  return out;
}
const int MAXN = 2e5 + 7;
int n, r, dep[MAXN], q, w[MAXN];
vector<int> G[MAXN];
struct SegmentTree {
  int root[MAXN], ls[MAXN << 5], rs[MAXN << 5], minn[MAXN << 5], tot;
  void modify(int l, int r, int pos, int x, int &rt) {
    rt = ++tot;
    minn[rt] = x;
    if (l + 1 == r) return;
    int mid = (l + r) >> 1;
    if (pos < mid)
      modify(l, mid, pos, x, ls[rt]);
    else
      modify(mid, r, pos, x, rs[rt]);
  }
  int merge(int u, int v, int l, int r) {
    if (!u or !v) return u ^ v;
    if (l + 1 == r) {
      int rt = ++tot;
      minn[rt] = min(minn[u], minn[v]);
      return rt;
    }
    int rt = ++tot;
    minn[rt] = 0x3f3f3f3f;
    int mid = (l + r) >> 1;
    ls[rt] = merge(ls[u], ls[v], l, mid);
    rs[rt] = merge(rs[u], rs[v], mid, r);
    if (ls[rt])
      ((minn[rt]) = (minn[rt]) < (minn[ls[rt]]) ? (minn[rt]) : (minn[ls[rt]]));
    if (rs[rt])
      ((minn[rt]) = (minn[rt]) < (minn[rs[rt]]) ? (minn[rt]) : (minn[rs[rt]]));
    return rt;
  }
  int qmin(int rt, int l, int r, int L, int R) {
    if (L >= r or l >= R or !rt) return 0x3f3f3f3f;
    if (L <= l and r <= R) return minn[rt];
    int mid = (l + r) >> 1;
    return min(qmin(ls[rt], l, mid, L, R), qmin(rs[rt], mid, r, L, R));
  }
} ST;
void dfs(int u, int par) {
  dep[u] = dep[par] + 1;
  ST.modify(1, n + 1, dep[u], w[u], ST.root[u]);
  for (int v : G[u]) {
    if (v == par) continue;
    dfs(v, u);
    ST.root[u] = ST.merge(ST.root[u], ST.root[v], 1, n + 1);
  }
}
void solve() {
  scanf("%d", &n);
  scanf("%d", &r);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    G[u] << v;
    G[v] << u;
  }
  dfs(r, 0);
  scanf("%d", &q);
  int lastans = 0;
  while (q--) {
    int x, k;
    scanf("%d", &x);
    scanf("%d", &k);
    x = (x + lastans) % n + 1;
    k = (k + lastans) % n;
    ((k) = (k) < (n - dep[x]) ? (k) : (n - dep[x]));
    printf("%d\n",
           lastans = ST.qmin(ST.root[x], 1, n + 1, dep[x], dep[x] + k + 1));
  }
}
int main() {
  solve();
  return 0;
}
