#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, totn;
int fa[N], L[N], R[N], d[N], tott;
int ch[7000010][2], minv[7000010], root[N];
vector<int> g[N], vd[N];
int a[N];
int add(int o, int l, int r, int qx, int qv) {
  int x = ++totn;
  ch[x][0] = ch[o][0], ch[x][1] = ch[o][1];
  minv[x] = min(minv[o], qv);
  if (l == r) return x;
  int mid = (l + r) >> 1;
  if (qx <= mid)
    ch[x][0] = add(ch[o][0], l, mid, qx, qv);
  else
    ch[x][1] = add(ch[o][1], mid + 1, r, qx, qv);
  return x;
}
int ask(int x, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return minv[x];
  int mid = (l + r) >> 1, ans = 0x7fffffff;
  if (ql <= mid) ans = min(ans, ask(ch[x][0], l, mid, ql, qr));
  if (mid < qr) ans = min(ans, ask(ch[x][1], mid + 1, r, ql, qr));
  return ans;
}
void dfs(int x) {
  L[x] = ++tott;
  for (auto p : g[x])
    if (p != fa[x]) {
      fa[p] = x;
      d[p] = d[x] + 1;
      dfs(p);
    }
  R[x] = tott;
}
int main() {
  int r, m, x, y;
  cin >> n >> r;
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  for (int i = (2); i <= (n); i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cin >> m;
  d[r] = 1;
  dfs(r);
  for (int i = (1); i <= (n); i++) vd[d[i]].push_back(i);
  minv[0] = 0x7fffffff;
  for (int i = (1); i <= (n); i++) {
    root[i] = root[i - 1];
    for (auto x : vd[i]) {
      root[i] = add(root[i], 1, n, L[x], a[x]);
    }
  }
  int lastans = 0;
  while (m--) {
    scanf("%d%d", &x, &y);
    x = (x + lastans) % n + 1;
    y = (y + lastans) % n;
    printf("%d\n", lastans = ask(root[min(n, d[x] + y)], 1, n, L[x], R[x]));
  }
  return 0;
}
