#include <bits/stdc++.h>
using namespace std;
const long long N = 100010;
const long long M = 1000010;
long long n, m, tot, tim, cnt, rt, head[N], dfn[N], low[N], d[N], root[N],
    siz[N], id[N];
struct Edge {
  long long suiv, ver;
} e[M << 1];
struct SegmentTree {
  long long l, r, mini;
  ;
  SegmentTree() { mini = 1000000010; }
} t[N * 50];
struct Node {
  long long val, id, dep;
  inline bool operator<(const Node& that) const { return dep < that.dep; }
} a[N];
inline bool cmp(long long x, long long y) { return d[x] < d[y]; }
inline void lnk(long long x, long long y) {
  e[++tot].ver = y;
  e[tot].suiv = head[x];
  head[x] = tot;
}
inline void dfs(long long x, long long fa) {
  d[x] = a[x].dep = d[fa] + 1;
  dfn[x] = ++tim;
  for (long long i = head[x]; i; i = e[i].suiv) {
    long long y = e[i].ver;
    if (y == fa) continue;
    dfs(y, x);
  }
  low[x] = tim;
}
inline void insert(long long p, long long& q, long long l, long long r,
                   long long d, long long val) {
  q = ++cnt;
  if (l == r) return t[q].mini = min(t[p].mini, val), void();
  long long mid = l + r >> 1;
  if (d <= mid) insert(t[p].l, t[q].l, l, mid, d, val), t[q].r = t[p].r;
  if (d > mid) insert(t[p].r, t[q].r, mid + 1, r, d, val), t[q].l = t[p].l;
  t[q].mini = min(t[t[q].l].mini, t[t[q].r].mini);
}
inline long long query(long long p, long long l, long long r, long long L,
                       long long R) {
  if (L <= l && r <= R) return t[p].mini;
  long long mid = l + r >> 1, res = 1ll << 60;
  if (L <= mid) res = min(res, query(t[p].l, l, mid, L, R));
  if (R > mid) res = min(res, query(t[p].r, mid + 1, r, L, R));
  return res;
}
signed main() {
  scanf("%lld%lld", &n, &rt);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i].val), a[i].id = i;
  for (long long i = 1, x, y; i < n; i++)
    scanf("%lld%lld", &x, &y), lnk(x, y), lnk(y, x);
  dfs(rt, 0);
  sort(a + 1, a + 1 + n);
  for (long long i = 1; i <= n; i++)
    insert(root[a[i - 1].dep], root[a[i].dep], 1, n, dfn[a[i].id], a[i].val);
  scanf("%lld", &m);
  long long x, y, ans = 0;
  while (m--) {
    scanf("%lld%lld", &x, &y);
    x = (x + ans) % n + 1, y = (y + ans) % n;
    printf("%lld\n",
           ans = query(root[min(d[x] + y, a[n].dep)], 1, n, dfn[x], low[x]));
  }
  return 0;
}
