#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int a[MAXN];
vector<int> G[MAXN];
int tot;
int dep[MAXN];
int rt[MAXN];
int val[MAXN << 6], ls[MAXN << 6], rs[MAXN << 6];
void push_up(int n) { val[n] = min(val[ls[n]], val[rs[n]]); }
void update(int p, int v, int l, int r, int &n) {
  n = ++tot;
  if (l == r) {
    val[n] = v;
    return;
  }
  int m = (l + r) / 2;
  if (p <= m) {
    update(p, v, l, m, ls[n]);
  } else {
    update(p, v, m + 1, r, rs[n]);
  }
  push_up(n);
}
int merging(int u, int v) {
  if (!u) return v;
  if (!v) return u;
  int t = ++tot;
  ls[t] = merging(ls[u], ls[v]);
  rs[t] = merging(rs[u], rs[v]);
  if (ls[t] || rs[t])
    push_up(t);
  else
    val[t] = min(val[u], val[v]);
  return t;
}
int query(int ql, int qr, int l, int r, int n) {
  if (!n) return INF;
  if (ql == l && qr == r) return val[n];
  int m = (l + r) / 2;
  if (qr <= m) return query(ql, qr, l, m, ls[n]);
  if (ql > m) return query(ql, qr, m + 1, r, rs[n]);
  return min(query(ql, m, l, m, ls[n]), query(m + 1, qr, m + 1, r, rs[n]));
}
void dfs(int u, int p) {
  update(dep[u], a[u], 1, MAXN - 1, rt[u]);
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == p) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u);
    rt[u] = merging(rt[u], rt[v]);
  }
}
int main() {
  val[0] = INF;
  int n, r;
  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);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dep[r] = 1;
  dfs(r, 0);
  int m;
  scanf("%d", &m);
  int lst = 0;
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = (x + lst) % n + 1;
    y = (y + lst) % n;
    printf("%d\n",
           lst = query(dep[x], min(MAXN - 1, dep[x] + y), 1, MAXN - 1, rt[x]));
  }
  return 0;
}
