#include <bits/stdc++.h>
using namespace std;
const int buf_size = 1e5 + 5;
char buf[buf_size], *S, *T;
inline char gc() {
  if (S == T) T = (S = buf) + fread(buf, 1, buf_size, stdin);
  return S != T ? *(S++) : EOF;
}
inline int in() {
  int x = 0, f = 1;
  char c = gc();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = gc();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = gc();
  return x * f;
}
const int N = 1e5 + 5, inf = 1e9;
int n, m, r, q, tot, ans;
int a[N], dep[N], dfn[N], out[N], root[N], rt[N];
vector<int> v[N];
int val[N << 5], ls[N << 5], rs[N << 5];
pair<int, int> h[N];
void dfs(int x, int fa) {
  dep[x] = dep[fa] + 1;
  dfn[x] = ++tot;
  for (int i = 0; i < v[x].size(); i++) {
    int y = v[x][i];
    if (y == fa) continue;
    dfs(y, x);
  }
  out[x] = tot;
}
int add(int pre, int l, int r, int x, int y) {
  int p = ++tot;
  val[p] = min(val[pre], y), ls[p] = ls[pre], rs[p] = rs[pre];
  if (l == r) return p;
  int mid = l + r >> 1;
  if (x <= mid)
    ls[p] = add(ls[pre], l, mid, x, y);
  else
    rs[p] = add(rs[pre], mid + 1, r, x, y);
  return p;
}
int query(int p, int l, int r, int ql, int qr) {
  if (!p) return inf;
  if (ql <= l && r <= qr) return val[p];
  int mid = l + r >> 1;
  int minn = inf;
  if (ql <= mid) minn = min(minn, query(ls[p], l, mid, ql, qr));
  if (qr > mid) minn = min(minn, query(rs[p], mid + 1, r, ql, qr));
  return minn;
}
int main() {
  n = in(), r = in();
  for (int i = 1; i <= n; i++) a[i] = in();
  val[0] = inf;
  for (int i = 1; i < n; i++) {
    int x = in(), y = in();
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(r, 0);
  for (int i = 1; i <= n; i++) h[i] = make_pair(dep[i], i);
  sort(h + 1, h + n + 1);
  for (int i = 1; i <= n; i++) {
    int x = h[i].second;
    root[i] = add(root[i - 1], 1, n, dfn[x], a[x]);
    rt[h[i].first] = root[i];
  }
  m = h[n].first;
  q = in();
  while (q--) {
    int x = in(), k = in();
    x = (x + ans) % n + 1, k = (k + ans) % n;
    ans = query(rt[min(dep[x] + k, m)], 1, n, dfn[x], out[x]);
    printf("%d\n", ans);
  }
  return 0;
}
