#include <bits/stdc++.h>
using namespace std;
int n, r, q, a[100005];
int dep[100005], dfn[100005], size[100005], maxdep, total, dfntotal;
int head[100005], cnt;
int root[100005];
struct data {
  int next, to;
  data(int next = 0, int to = 0) : next(next), to(to) {}
} edge[100005 << 1];
struct segment {
  int l, r, v;
  segment(int l = 0, int r = 0, int v = 0x3f3f3f3f) : l(l), r(r), v(v) {}
} t[100005 << 5];
int read() {
  char c = getchar();
  int x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
void connect(int u, int v) {
  edge[++cnt] = data(head[u], v);
  head[u] = cnt;
}
void append(int l, int r, int p, int c, int& u, int v) {
  t[u = ++total] = t[v];
  t[u].v = min(t[u].v, c);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (p <= mid)
    append(l, mid, p, c, t[u].l, t[v].l);
  else
    append(mid + 1, r, p, c, t[u].r, t[v].r);
}
int query(int l, int r, int p, int q, int u) {
  if (!u) return 0x3f3f3f3f;
  if (p <= l && r <= q) return t[u].v;
  int mid = (l + r) >> 1, res = 0x3f3f3f3f;
  if (p <= mid) res = min(res, query(l, mid, p, q, t[u].l));
  if (q > mid) res = min(res, query(mid + 1, r, p, q, t[u].r));
  return res;
}
void DFS(int u, int pre) {
  dfn[u] = ++dfntotal;
  dep[u] = dep[pre] + 1;
  size[u] = 1;
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    DFS(v, u);
    size[u] += size[v];
  }
}
void BFS() {
  queue<int> q;
  q.push(r);
  int last = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    append(1, n, dfn[u], a[u], root[dep[u]], last);
    maxdep = max(maxdep, dep[u]);
    for (int i = head[u]; i; i = edge[i].next) {
      int v = edge[i].to;
      if (dep[v] < dep[u]) continue;
      q.push(v);
    }
    last = root[dep[u]];
  }
}
int main() {
  n = read();
  r = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    connect(u, v);
    connect(v, u);
  }
  DFS(r, 0);
  BFS();
  int last = 0;
  q = read();
  while (q--) {
    int x = (read() + last) % n + 1, k = (read() + last) % n;
    printf("%d\n", last = query(1, n, dfn[x], dfn[x] + size[x] - 1,
                                root[min(dep[x] + k, maxdep)]));
  }
}
