#include <bits/stdc++.h>
using namespace std;
int n, rt, t[100010], sum[8000010], l[8000010], r[8000010], cnt;
int dep[100010], a[100010], fa[100010];
vector<int> vc[100010];
void ins(int &p, int lf, int rg, int w, int x) {
  if (!p) {
    p = ++cnt;
  }
  if (lf == rg) {
    sum[p] = x;
    return;
  }
  sum[p] = min(sum[p], x);
  int mid = (lf + rg) >> 1;
  if (w <= mid) {
    ins(l[p], lf, mid, w, x);
  }
  if (mid < w) {
    ins(r[p], mid + 1, rg, w, x);
  }
}
int merge(int x, int y) {
  if (!x || !y) {
    return x + y;
  }
  int p = ++cnt;
  sum[p] = min(sum[x], sum[y]);
  l[p] = merge(l[x], l[y]);
  r[p] = merge(r[x], r[y]);
  return p;
}
int query(int o, int lf, int rg, int ll, int rr) {
  if (!o) {
    return 0x3f3f3f3f;
  }
  if (ll <= lf && rg <= rr) {
    return sum[o];
  }
  int ans = 0x3f3f3f3f;
  int mid = (lf + rg) >> 1;
  if (ll <= mid) {
    ans = min(ans, query(l[o], lf, mid, ll, rr));
  }
  if (mid < rr) {
    ans = min(ans, query(r[o], mid + 1, rg, ll, rr));
  }
  return ans;
}
void dfs(int u) {
  ins(t[u], 1, n, dep[u], a[u]);
  for (auto v : vc[u]) {
    if (v == fa[u]) {
      continue;
    }
    dep[v] = dep[u] + 1;
    fa[v] = u;
    dfs(v);
    t[u] = merge(t[u], t[v]);
  }
}
int main() {
  memset(sum, 0x3f, sizeof(sum));
  cin >> n >> rt;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    vc[x].push_back(y);
    vc[y].push_back(x);
  }
  dep[rt] = 1;
  dfs(rt);
  int q, las = 0;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int x, k;
    scanf("%d%d", &x, &k);
    x = (x + las) % n + 1, k = (k + las) % n;
    cout << (las = query(t[x], 1, n, dep[x], min(dep[x] + k, n))) << "\n";
  }
}
