#include <bits/stdc++.h>
using namespace std;
vector<long long> g[100005], gg[100005], v[100005], down[100005][17];
long long n, root, cnt, q, ans;
long long cc[100005], c[100005], ne[100005], depth[100005], childdepth[100005];
long long up[100005][17], val[100005][17], lefty[100005][17],
    righty[100005][17];
long long segtree[17][400005], ltree[17][400005], rtree[17][400005];
void label(long long u, long long p, long long d) {
  v[d].push_back(u);
  for (auto vv : gg[u])
    if (vv != p) label(vv, u, d + 1);
}
void dfs(long long u, long long p) {
  depth[u] = depth[p] + 1;
  childdepth[u] = depth[u];
  up[u][0] = p;
  down[p][0].push_back(u);
  val[p][0] = min(val[p][0], c[u]);
  lefty[p][0] = min(lefty[p][0], u);
  righty[p][0] = max(righty[p][0], u);
  for (long long i = 1; i <= 16; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
    lefty[up[u][i]][i] = min(lefty[up[u][i]][i], u);
    righty[up[u][i]][i] = max(righty[up[u][i]][i], u);
    down[up[u][i]][i].push_back(u);
  }
  for (auto v : g[u])
    if (v != p) {
      dfs(v, u);
      childdepth[u] = max(childdepth[u], childdepth[v]);
    }
}
void build(long long id, long long l, long long r) {
  if (l == r) {
    for (long long i = 0; i <= 16; i++) {
      segtree[i][id] = val[l][i];
      ltree[i][id] = lefty[l][i];
      rtree[i][id] = righty[l][i];
    }
    return;
  }
  long long m = (l + r) / 2;
  build(id * 2, l, m);
  build(id * 2 + 1, m + 1, r);
  for (long long i = 0; i <= 16; i++) {
    segtree[i][id] = min(segtree[i][id * 2], segtree[i][id * 2 + 1]);
    ltree[i][id] = min(ltree[i][id * 2], ltree[i][id * 2 + 1]);
    rtree[i][id] = max(rtree[i][id * 2], rtree[i][id * 2 + 1]);
  }
}
long long get_min(long long id, long long l, long long r, long long tl,
                  long long tr, long long bit) {
  if (l > tr || r < tl) return 1000000000000000000;
  if (l >= tl && r <= tr) return segtree[bit][id];
  long long m = (l + r) / 2;
  return min(get_min(id * 2, l, m, tl, tr, bit),
             get_min(id * 2 + 1, m + 1, r, tl, tr, bit));
}
long long get_l(long long id, long long l, long long r, long long tl,
                long long tr, long long bit) {
  if (l > tr || r < tl) return 1000000000000000000;
  if (l >= tl && r <= tr) return ltree[bit][id];
  long long m = (l + r) / 2;
  return min(get_l(id * 2, l, m, tl, tr, bit),
             get_l(id * 2 + 1, m + 1, r, tl, tr, bit));
}
long long get_r(long long id, long long l, long long r, long long tl,
                long long tr, long long bit) {
  if (l > tr || r < tl) return 0;
  if (l >= tl && r <= tr) return rtree[bit][id];
  long long m = (l + r) / 2;
  return max(get_r(id * 2, l, m, tl, tr, bit),
             get_r(id * 2 + 1, m + 1, r, tl, tr, bit));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> root;
  for (long long i = 1; i <= n; i++) cin >> cc[i];
  for (long long i = 1; i <= n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    gg[a].push_back(b);
    gg[b].push_back(a);
  }
  label(root, 0, 1);
  for (long long i = 1; i <= 100000; i++) {
    for (auto j : v[i]) ne[j] = ++cnt;
  }
  for (long long i = 1; i <= n; i++) c[ne[i]] = cc[i];
  for (long long i = 1; i <= n; i++) {
    for (auto &j : gg[i]) j = ne[j];
  }
  for (long long i = 1; i <= n; i++) g[ne[i]] = gg[i];
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j <= 16; j++) {
      val[i][j] = 1000000000000000000;
      lefty[i][j] = 1000000000000000000;
    }
  }
  dfs(1, 0);
  for (long long j = 1; j <= 16; j++) {
    for (long long i = n; i >= 1; i--) {
      long long r = 1000000000000000000;
      for (auto v : down[i][j - 1]) r = min(r, val[v][j - 1]);
      val[i][j] = min(r, val[i][j - 1]);
    }
  }
  build(1, 1, n);
  cin >> q;
  while (q--) {
    long long x, k;
    cin >> x >> k;
    x = (x + ans) % n + 1;
    k = (k + ans) % n;
    x = ne[x];
    k = min(k, childdepth[x] - depth[x]);
    ans = c[x];
    long long curl = x, curr = x;
    for (long long i = 16; i >= 0; i--)
      if ((1 << i) <= k) {
        k -= (1 << i);
        ans = min(ans, get_min(1, 1, n, curl, curr, i));
        long long tl = get_l(1, 1, n, curl, curr, i);
        long long tr = get_r(1, 1, n, curl, curr, i);
        curl = tl;
        curr = tr;
      }
    cout << ans << "\n";
  }
}
