#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int w = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    w = (w << 3) + (w << 1) + ch - 48;
    ch = getchar();
  }
  return w * f;
}
int n, m, tot, root[500010], r, a[500010], maxx;
bool debug;
struct DSU_ON_TREE {
  struct Node {
    int ch[2], val;
  } st[100000 * 64];
  inline void pushup(int x) {
    st[x].val = min(st[st[x].ch[0]].val, st[st[x].ch[1]].val);
  }
  inline int change(int p, int l, int r, int pos, int val) {
    if (!p) p = ++tot;
    st[p].val = 0x3f3f3f3f;
    if (l == r) {
      st[p].val = min(st[p].val, val);
      return p;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      st[p].ch[0] = change(st[p].ch[0], l, mid, pos, val);
    else
      st[p].ch[1] = change(st[p].ch[1], mid + 1, r, pos, val);
    pushup(p);
    return p;
  }
  inline int merge(int x, int y, int l, int r) {
    if (!x || !y) return x | y;
    int p = ++tot;
    int mid = (l + r) >> 1;
    if (l == r) {
      st[p].val = min(st[x].val, st[y].val);
      return p;
    }
    st[p].ch[0] = merge(st[x].ch[0], st[y].ch[0], l, mid);
    st[p].ch[1] = merge(st[x].ch[1], st[y].ch[1], mid + 1, r);
    pushup(p);
    return p;
  }
  inline int query(int p, int L, int R, int l, int r) {
    if (!p) return 0x3f3f3f3f;
    if (L <= l && R >= r) {
      return st[p].val;
    }
    int mid = (l + r) >> 1;
    int now = 0x3f3f3f3f;
    if (L <= mid) now = min(now, query(st[p].ch[0], L, R, l, mid));
    if (R > mid) now = min(now, query(st[p].ch[1], L, R, mid + 1, r));
    return now;
  }
} DSU;
int cnt, head[500010];
struct Edge {
  int from, to, next;
} edge[500010];
inline void addedge(int u, int v) {
  cnt++;
  edge[cnt].from = u;
  edge[cnt].to = v;
  edge[cnt].next = head[u];
  head[u] = cnt;
}
int now[500010], b[500010];
int depth[500010], size[500010];
inline void dfs(int u, int fa) {
  depth[u] = depth[fa] + 1;
  root[u] = DSU.change(root[u], 1, maxx, depth[u], now[u]);
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
    root[u] = DSU.merge(root[u], root[v], 1, maxx);
  }
}
int main() {
  DSU.st[0].val = 0x3f3f3f3f;
  n = read();
  r = read();
  maxx = n;
  for (int i = 1; i <= n; i++) {
    now[i] = read();
  }
  for (int i = 1; i < n; i++) {
    int x = read();
    int y = read();
    addedge(x, y);
    addedge(y, x);
  }
  dfs(r, 0);
  m = read();
  int lst = 0;
  while (m--) {
    int p = read();
    int q = read();
    p = (p + lst) % n + 1;
    q = (q + lst) % n;
    int ans = DSU.query(root[p], depth[p], depth[p] + q, 1, maxx);
    printf("%d\n", ans);
    lst = ans;
  }
  return 0;
}
