#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
inline int read() {
  int x(0), w(1);
  char c = getchar();
  while (c ^ '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') w = -1, c = getchar();
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * w;
}
int n, M, las, x, y, cnt, R, a[N], rt[N], dep[N], ls[N << 6], rs[N << 6],
    v[N << 6];
int head[N], nxt[N << 1], to[N << 1], cnte;
inline void add(int u, int v) {
  to[++cnte] = v;
  nxt[cnte] = head[u];
  head[u] = cnte;
}
void debug(int u) {
  if (!u) return;
  printf("u=%d v=%d ls=%d rs=%d\n", u, v[u], ls[u], rs[u]);
  debug(ls[u]);
  debug(rs[u]);
}
inline void pushup(int u) { v[u] = min(v[ls[u]], v[rs[u]]); }
int merge(int a, int b, int l, int r) {
  if (!a || !b) return a | b;
  int u = ++cnt;
  if (l == r) {
    v[u] = min(v[a], v[b]);
    return u;
  }
  int mid = (l + r) >> 1;
  ls[u] = merge(ls[a], ls[b], l, mid);
  rs[u] = merge(rs[a], rs[b], mid + 1, r);
  pushup(u);
  return u;
}
int modify(int u, int l, int r, int x, int k) {
  if (!u) u = ++cnt;
  if (l == r) {
    v[u] = k;
    return u;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    ls[u] = modify(ls[u], l, mid, x, k);
  else
    rs[u] = modify(rs[u], mid + 1, r, x, k);
  pushup(u);
  return u;
}
int query(int u, int l, int r, int x, int y) {
  if (l > y || r < x) return 0x3f3f3f3f;
  if (x <= l && r <= y) return v[u];
  int mid = (l + r) >> 1;
  return min(query(ls[u], l, mid, x, y), query(rs[u], mid + 1, r, x, y));
}
void dfs(int u, int Fa) {
  rt[u] = modify(rt[u], 1, n, dep[u], a[u]);
  for (int i = head[u]; i; i = nxt[i]) {
    if (to[i] == Fa) continue;
    dep[to[i]] = dep[u] + 1;
    dfs(to[i], u);
    rt[u] = merge(rt[u], rt[to[i]], 1, n);
  }
}
int main() {
  memset(v, 0x3f3f3f3f, sizeof(v));
  n = read(), R = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i < n; ++i) {
    x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  for (int i = 1; i <= n; ++i) rt[i] = ++cnt;
  dep[R] = 1;
  dfs(R, -1);
  M = read();
  while (M--) {
    x = read(), y = read();
    x = (x + las) % n + 1;
    y = (y + las) % n;
    las = query(rt[x], 1, n, dep[x], dep[x] + y);
    printf("%d\n", las);
  }
  return 0;
}
