#include <bits/stdc++.h>
using namespace std;
const int maxm = 2e5 + 5;
vector<int> g[maxm];
int a[maxm];
int n, rt;
int ans;
int d[maxm];
int lc[maxm * 40], rc[maxm * 40], mi[maxm * 40];
int r[maxm], tot;
void pushup(int k) { mi[k] = min(mi[lc[k]], mi[rc[k]]); }
void update(int x, int val, int l, int r, int &k) {
  if (!k) k = ++tot;
  if (l == r) {
    mi[k] = val;
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid)
    update(x, val, l, mid, lc[k]);
  else
    update(x, val, mid + 1, r, rc[k]);
  pushup(k);
}
int merged(int x, int y) {
  if (!x || !y) return x + y;
  int k = ++tot;
  lc[k] = merged(lc[x], lc[y]);
  rc[k] = merged(rc[x], rc[y]);
  mi[k] = min(mi[x], mi[y]);
  return k;
}
int ask(int st, int ed, int l, int r, int k) {
  if (st <= l && ed >= r) return mi[k];
  int mid = (l + r) / 2;
  int ans = 2e9;
  if (st <= mid) ans = min(ans, ask(st, ed, l, mid, lc[k]));
  if (ed > mid) ans = min(ans, ask(st, ed, mid + 1, r, rc[k]));
  return ans;
}
void dfs(int x, int fa) {
  update(d[x], a[x], 1, n, r[x]);
  for (int v : g[x]) {
    if (v == fa) continue;
    d[v] = d[x] + 1;
    dfs(v, x);
    r[x] = merged(r[x], r[v]);
  }
}
signed main() {
  mi[0] = 2e9;
  scanf("%d%d", &n, &rt);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  d[rt] = 1;
  dfs(rt, rt);
  int m;
  scanf("%d", &m);
  while (m--) {
    int p, q;
    scanf("%d%d", &p, &q);
    int x = ((p + ans) % n) + 1, k = (q + ans) % n;
    ans = ask(d[x], min(n, d[x] + k), 1, n, r[x]);
    printf("%d\n", ans);
  }
  return 0;
}
