#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int rt[N], h[N], nex[N << 1], to[N << 1], cur;
const int inf = 2e9;
void add_edge(int x, int y) {
  to[++cur] = y;
  nex[cur] = h[x];
  h[x] = cur;
}
struct segmenttree {
  struct node {
    int lc, rc, mn;
  } s[N * 40];
  int tot;
  segmenttree() {}
  void pushup(int rt) {
    int lm = s[rt].lc ? s[s[rt].lc].mn : inf;
    int rm = s[rt].rc ? s[s[rt].rc].mn : inf;
    s[rt].mn = min(lm, rm);
  }
  void update(int &rt, int l, int r, int pos, int val) {
    if (!rt) rt = ++tot;
    if (l == r) {
      s[rt].mn = val;
      return;
    }
    int mid = l + r >> 1;
    if (pos <= mid)
      update(s[rt].lc, l, mid, pos, val);
    else
      update(s[rt].rc, mid + 1, r, pos, val);
    pushup(rt);
  }
  int query(int rt, int l, int r, int L, int R) {
    if (!rt) return inf;
    if (L <= l && R >= r) return s[rt].mn;
    int mid = l + r >> 1, ret = inf;
    if (L <= mid) ret = query(s[rt].lc, l, mid, L, R);
    if (R > mid) ret = min(ret, query(s[rt].rc, mid + 1, r, L, R));
    return ret;
  }
  int merge(int x, int y) {
    if (!x || !y) return x + y;
    int rt = ++tot;
    s[rt].mn = min(s[x].mn, s[y].mn);
    s[rt].lc = merge(s[x].lc, s[y].lc);
    s[rt].rc = merge(s[x].rc, s[y].rc);
    return rt;
  }
} tr;
int n, treert, val[N], dep[N];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  tr.update(rt[u], 1, n, dep[u], val[u]);
  for (int i = h[u]; i; i = nex[i]) {
    int v = to[i];
    if (v == fa) continue;
    dfs(v, u);
    rt[u] = tr.merge(rt[u], rt[v]);
  }
}
int main() {
  scanf("%d%d", &n, &treert);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  int q;
  dfs(treert, 0);
  scanf("%d", &q);
  int lans = 0;
  for (int i = 1; i <= q; i++) {
    int x, k;
    scanf("%d%d", &x, &k);
    x = (x + lans) % n + 1;
    k = (k + lans) % n;
    lans = tr.query(rt[x], 1, n, dep[x], min(dep[x] + k, n));
    printf("%d\n", lans);
  }
  return 0;
}
