#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, INF = 1e9 + 10;
int n, rt, tot;
int fir[N], root[N], v[N], dep[N];
struct edge {
  int to;
  int nxt;
} e[2 * N];
inline void add(int x, int y) {
  e[++tot].to = y;
  e[tot].nxt = fir[x];
  fir[x] = tot;
  e[++tot].to = x;
  e[tot].nxt = fir[y];
  fir[y] = tot;
}
struct tree {
  int cnt;
  int son[40 * N][2], val[40 * N];
  tree() {
    cnt = 0;
    memset(val, 0x3f, sizeof(val));
  }
  inline int merge(int p, int q, int l, int r) {
    if (p == 0) return q;
    if (q == 0) return p;
    int np = ++cnt;
    if (l == r) {
      val[np] = min(val[p], val[q]);
      return np;
    }
    int mid = (l + r) / 2;
    son[np][0] = merge(son[p][0], son[q][0], l, mid);
    son[np][1] = merge(son[p][1], son[q][1], mid + 1, r);
    val[np] = min(val[son[np][0]], val[son[np][1]]);
    return np;
  }
  inline void change(int &p, int l, int r, int pos, int c) {
    if (p == 0) p = ++cnt;
    if (l == r) {
      val[p] = c;
      return;
    }
    int mid = (l + r) / 2;
    if (pos <= mid)
      change(son[p][0], l, mid, pos, c);
    else
      change(son[p][1], mid + 1, r, pos, c);
    val[p] = min(val[son[p][0]], val[son[p][1]]);
  }
  inline int query(int p, int l, int r, int x, int y) {
    if (p == 0) return INF;
    if (x <= l && y >= r) return val[p];
    int mid = (l + r) / 2, ans = INF;
    if (x <= mid) ans = min(ans, query(son[p][0], l, mid, x, y));
    if (y > mid) ans = min(ans, query(son[p][1], mid + 1, r, x, y));
    return ans;
  }
} t;
inline void dfs(int p, int fa) {
  root[p] = ++t.cnt;
  t.change(root[p], 1, n, dep[p], v[p]);
  for (int i = fir[p]; i; i = e[i].nxt) {
    int q = e[i].to;
    if (q == fa) continue;
    dep[q] = dep[p] + 1;
    dfs(q, p);
    root[p] = t.merge(root[p], root[q], 1, n);
  }
}
int main() {
  int m, a, b, last = 0;
  scanf("%d%d", &n, &rt);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    add(a, b);
  }
  dep[rt] = 1, dfs(rt, 0);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    a = (a + last) % n + 1, b = (b + last) % n;
    last = t.query(root[a], 1, n, dep[a], min(dep[a] + b, n));
    printf("%d\n", last);
  }
  return 0;
}
