#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18L;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int N = 2e7;
const int Mod = 1e9 + 7;
vector<int> g[maxn];
int dep[maxn], root[maxn], n, a[maxn], r, m;
int mn[N], ls[N], rs[N], cnt;
int newnode() {
  ++cnt;
  ls[cnt] = rs[cnt] = 0;
  return cnt;
}
void Insert(int &x, int L, int R, int pos, int v) {
  x = newnode();
  mn[x] = v;
  if (L == R) return;
  int mid = (L + R) >> 1;
  if (mid >= pos)
    Insert(ls[x], L, mid, pos, v);
  else
    Insert(rs[x], mid + 1, R, pos, v);
}
int Merge(int x, int y, int L, int R) {
  if (!x) return y;
  if (!y) return x;
  int now = newnode();
  mn[now] = min(mn[x], mn[y]);
  if (L == R) return now;
  int mid = (L + R) >> 1;
  ls[now] = Merge(ls[x], ls[y], L, mid);
  rs[now] = Merge(rs[x], rs[y], mid + 1, R);
  return now;
}
int query(int x, int L, int R, int pos) {
  if (R <= pos) return mn[x];
  if (!x) return inf;
  int mid = (L + R) >> 1;
  if (mid >= pos) return query(ls[x], L, mid, pos);
  return min(query(ls[x], L, mid, pos), query(rs[x], mid + 1, R, pos));
}
void dfs(int u, int fa) {
  Insert(root[u], 1, n, dep[u], a[u]);
  for (int i = 0; i < ((int)(g[u]).size()); i++) {
    int v = g[u][i];
    if (v == fa) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u);
    root[u] = Merge(root[u], root[v], 1, n);
  }
}
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);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dep[r] = 1;
  mn[0] = inf;
  dfs(r, r);
  scanf("%d", &m);
  int ans = 0;
  while (m--) {
    int p, q;
    scanf("%d%d", &p, &q);
    p = (p + ans) % n + 1;
    q = (q + ans) % n;
    ans = query(root[p], 1, n, min(dep[p] + q, n));
    printf("%d\n", ans);
  }
  return 0;
}
