#include <bits/stdc++.h>
using namespace std;
int n, Q, x, y, r, p, q, kk, cnt, lastans, a[500005], d[500005 * 16],
    ls[500005 * 16], rs[500005 * 16], rt[500005], dep[500005], head[500005];
struct Tree {
  int nxt, to;
} e[500005];
inline void link(int x, int y) {
  e[++kk].nxt = head[x];
  e[kk].to = y;
  head[x] = kk;
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  int ret = ++cnt;
  d[ret] = 1e9;
  ls[ret] = merge(ls[x], ls[y]);
  rs[ret] = merge(rs[x], rs[y]);
  d[ret] = min(d[x], d[y]);
  return ret;
}
void insert(int &k, int l, int r, int x, int y) {
  if (!k) k = ++cnt;
  if (l == r) {
    d[k] = y;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    insert(ls[k], l, mid, x, y);
  else
    insert(rs[k], mid + 1, r, x, y);
  d[k] = min(d[ls[k]], d[rs[k]]);
}
int query(int k, int l, int r, int x, int y) {
  if (!k) return 1e9;
  if (x <= l && y >= r) return d[k];
  int mid = (l + r) >> 1;
  if (y <= mid)
    return query(ls[k], l, mid, x, y);
  else if (x > mid)
    return query(rs[k], mid + 1, r, x, y);
  else
    return min(query(ls[k], l, mid, x, mid),
               query(rs[k], mid + 1, r, mid + 1, y));
}
void dfs1(int u, int fa, int de) {
  dep[u] = de;
  insert(rt[u], 1, n, de, a[u]);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs1(v, u, de + 1);
    rt[u] = merge(rt[u], rt[v]);
  }
}
int main() {
  scanf("%d%d", &n, &r);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    link(x, y);
    link(y, x);
  }
  d[0] = 1e9;
  scanf("%d", &Q);
  dfs1(r, -1, 1);
  while (Q--) {
    scanf("%d%d", &p, &q);
    int x = (p + lastans) % n + 1;
    int k = (q + lastans) % n;
    printf("%d\n", lastans = query(rt[x], 1, n, dep[x], min(n, dep[x] + k)));
  }
  return 0;
}
