#include <bits/stdc++.h>
using namespace std;
vector<int> F[100010];
int n, ROOT, q, len = 0;
struct node {
  int x, y, next;
} a[200010];
int last[200010], val[100010], dep[100010], size[100010], id[100010],
    root[100010], ls[2000010], rs[2000010], Val[2000010];
void ins(int x, int y) {
  a[++len] = (node){x, y, last[x]};
  last[x] = len;
}
int cnt = 0;
void dfs(int x, int fa) {
  id[x] = ++cnt;
  size[x] = 1;
  for (int i = last[x]; i; i = a[i].next) {
    int y = a[i].y;
    if (y == fa) continue;
    dep[y] = dep[x] + 1;
    F[dep[y]].push_back(y);
    dfs(y, x);
    size[x] += size[y];
  }
}
int Len = 0;
void build(int &now, int l, int r) {
  now = ++Len;
  Val[now] = (int)(1e9);
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls[now], l, mid), build(rs[now], mid + 1, r);
}
void change(int last, int &now, int l, int r, int x, int d) {
  now = ++Len;
  if (l == r) {
    Val[now] = d;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    rs[now] = rs[last], change(ls[last], ls[now], l, mid, x, d);
  else
    ls[now] = ls[last], change(rs[last], rs[now], mid + 1, r, x, d);
  Val[now] = min(Val[ls[now]], Val[rs[now]]);
}
int solve(int now, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return Val[now];
  int mid = (l + r) >> 1;
  if (rr <= mid)
    return solve(ls[now], l, mid, ll, rr);
  else if (ll > mid)
    return solve(rs[now], mid + 1, r, ll, rr);
  else
    return min(solve(ls[now], l, mid, ll, rr),
               solve(rs[now], mid + 1, r, ll, rr));
}
int main() {
  int x, y, maxdep = 0, lastans = 0;
  scanf("%d %d", &n, &ROOT);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    ins(x, y), ins(y, x);
  }
  dep[ROOT] = 1;
  F[1].push_back(ROOT);
  dfs(ROOT, 0);
  build(root[0], 1, n);
  for (int i = 1; i <= n; i++) {
    if (!F[i].size()) break;
    maxdep = i;
    root[i] = root[i - 1];
    for (int j = 0; j < F[i].size(); j++)
      change(root[i], root[i], 1, n, id[F[i][j]], val[F[i][j]]);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    x = (x + lastans) % n + 1, y = (y + lastans) % n;
    printf("%d\n", lastans = solve(root[min(dep[x] + y, maxdep)], 1, n, id[x],
                                   id[x] + size[x] - 1));
  }
}
