#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30), N = 200000;
int cnt, n, r, Q, deep[N], dfn[N], size[N], a[N], root[N << 2], len, last;
struct node {
  int lson, rson, Min = INF;
} t[10000000];
vector<int> V[N];
void dfs(int x, int fat) {
  dfn[x] = ++cnt;
  deep[x] = deep[fat] + 1;
  size[x] = 1;
  for (int i = 0, s = V[x].size(); i < s; i++)
    if (V[x][i] != fat) dfs(V[x][i], x), size[x] += size[V[x][i]];
}
void InInsert(int i, int l, int r, int Dfn, int val) {
  t[i].Min = min(t[i].Min, val);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (mid >= Dfn) {
    if (!t[i].lson) t[i].lson = ++len;
    InInsert(t[i].lson, l, mid, Dfn, val);
  } else {
    if (!t[i].rson) t[i].rson = ++len;
    InInsert(t[i].rson, mid + 1, r, Dfn, val);
  }
}
void OutInsert(int i, int l, int r, int dep, int Dfn, int val) {
  if (!root[i]) root[i] = ++len;
  InInsert(root[i], 1, n, Dfn, val);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (mid >= dep)
    OutInsert(i << 1, l, mid, dep, Dfn, val);
  else
    OutInsert(i << 1 | 1, mid + 1, r, dep, Dfn, val);
}
int InQuery(int i, int l, int r, int dfnb, int dfne) {
  if (!i) return INF;
  if (l >= dfnb && r <= dfne) return t[i].Min;
  int mid = (l + r) >> 1, ans = INF;
  if (mid >= dfnb) ans = min(ans, InQuery(t[i].lson, l, mid, dfnb, dfne));
  if (mid < dfne) ans = min(ans, InQuery(t[i].rson, mid + 1, r, dfnb, dfne));
  return ans;
}
int OutQuery(int i, int l, int r, int depb, int depe, int dfnb, int dfne) {
  if (l >= depb && r <= depe) return InQuery(root[i], 1, n, dfnb, dfne);
  int mid = (l + r) >> 1, ans = INF;
  if (mid >= depb)
    ans = min(ans, OutQuery(i << 1, l, mid, depb, depe, dfnb, dfne));
  if (mid < depe)
    ans = min(ans, OutQuery(i << 1 | 1, mid + 1, r, depb, depe, dfnb, dfne));
  return ans;
}
int main() {
  scanf("%d%d", &n, &r);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    V[u].push_back(v);
    V[v].push_back(u);
  }
  dfs(r, 0);
  for (int i = 1; i <= n; i++) OutInsert(1, 1, n, deep[i], dfn[i], a[i]);
  scanf("%d", &Q);
  while (Q--) {
    int x, k;
    scanf("%d%d", &x, &k);
    x = (x + last) % n + 1;
    k = (k + last) % n;
    last = OutQuery(1, 1, n, deep[x], min(deep[x] + k, n), dfn[x],
                    dfn[x] + size[x] - 1);
    printf("%d\n", last);
  }
}
