#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, y = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') y = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return y ? -x : x;
}
template <typename T>
inline T read() {
  T x = 0;
  int y = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') y = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return y ? -x : x;
}
inline int ran() {
  static int seed = 703;
  return seed = int(seed * 48271LL % 2147483647);
}
int root[100005], fa[100005], h[100005], line[100005], pos[100005], id[100005],
    lo[100005], did[100005], dep[100005], max_dep, head, tail, num, all, gen, n,
    len;
struct edge {
  int pre, to;
} e[100005 << 1];
inline void add(int from, int to) {
  e[++num].pre = h[from], h[from] = num, e[num].to = to;
}
struct Chairman_Tree {
  int ls[100005 << 5], rs[100005 << 5], mi[100005 << 5], cnt;
  void build(int poi, int l, int r, int &node, int ol, int d) {
    node = ++cnt;
    mi[node] = min(mi[ol], d);
    if (l == r) return;
    int mid = l + r >> 1;
    if (poi <= mid)
      rs[node] = rs[ol], build(poi, l, mid, ls[node], ls[ol], d);
    else
      ls[node] = ls[ol], build(poi, mid + 1, r, rs[node], rs[ol], d);
  }
  int ask(int L, int R, int l, int r, int node) {
    if (!node) return 0x3f3f3f3f;
    if (L <= l && R >= r) return mi[node];
    int mid = l + r >> 1, ans = 0x3f3f3f3f;
    if (L <= mid) ans = ask(L, R, l, mid, ls[node]);
    if (R > mid) ans = min(ans, ask(L, R, mid + 1, r, rs[node]));
    return ans;
  }
  Chairman_Tree() { mi[0] = 0x3f3f3f3f; }
} ct;
struct point {
  int deep, seg, low, dat;
} p[100005];
void dfs(int node = gen) {
  id[node] = p[node].seg = ++all;
  for (register int i = h[node]; i; i = e[i].pre) {
    int x = e[i].to;
    if (!p[x].seg) fa[x] = node, dfs(x);
  }
  lo[node] = p[node].low = all;
}
void bfs() {
  line[1] = gen, dep[gen] = p[gen].deep = tail = 1;
  while (head < tail) {
    int node = line[++head];
    for (register int i = h[node]; i; i = e[i].pre) {
      int x = e[i].to;
      if (x != fa[node]) {
        line[++tail] = x;
        dep[x] = p[x].deep = p[node].deep + 1;
      }
    }
  }
  max_dep = p[line[tail]].deep;
}
inline bool cmp(point x, point y) { return x.deep < y.deep; }
signed main() {
  n = read(), gen = read();
  for (register int i = 1; i <= n; ++i) p[i].dat = read();
  for (register int i = 1; i < n; ++i) {
    int x = read(), y = read();
    add(x, y), add(y, x);
  }
  dfs(), bfs();
  sort(p + 1, p + 1 + n, cmp);
  for (register int i = 1; i <= n; ++i) {
    ct.build(p[i].seg, 1, n, root[i], root[i - 1], p[i].dat);
    if (p[i].deep != p[i - 1].deep) did[p[i - 1].deep] = i - 1;
  }
  did[p[n].deep] = n;
  int m = read(), ans = 0;
  while (m--) {
    int x = (read() + ans) % n + 1, k = (read() + ans) % n;
    printf("%d\n", ans = ct.ask(id[x], lo[x], 1, n,
                                root[did[min(dep[x] + k, max_dep)]]));
  }
}
