#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;
int cnt, head[MAXN], tot;
int n, tim, a[MAXN], root[MAXN];
struct Poi {
  int w, dfn, dep, col;
} poi[MAXN];
bool cmp(int a, int b) { return poi[a].dep < poi[b].dep; }
struct Edge {
  int v, nex;
} edge[MAXN * 2];
struct Node {
  int l, r, m;
} node[MAXN * 20];
void add(int u, int v) {
  edge[cnt] = {v, head[u]};
  head[u] = cnt++;
}
void dfs(int u, int fa) {
  poi[u].dep = poi[fa].dep + 1;
  poi[u].dfn = ++tim;
  for (int i = head[u]; ~i; i = edge[i].nex) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs(v, u);
  }
  poi[u].col = tim;
}
void up(int rt) { node[rt].m = min(node[node[rt].l].m, node[node[rt].r].m); }
void update(int &rt, int l, int r, int k, int x) {
  node[++tot] = node[rt];
  rt = tot;
  if (l == r) {
    node[rt].m = x;
    return;
  }
  int mid = ((l + r) >> 1);
  if (k <= mid)
    update(node[rt].l, l, mid, k, x);
  else
    update(node[rt].r, mid + 1, r, k, x);
  up(rt);
}
int bin(int x) {
  int l = 1, r = n;
  while (l <= r) {
    int mid = ((l + r) >> 1);
    if (poi[a[mid]].dep <= x)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return r;
}
int query(int rt, int l, int r, int L, int R) {
  if (l == L && r == R) return node[rt].m;
  int mid = ((l + r) >> 1);
  if (R <= mid)
    return query(node[rt].l, l, mid, L, R);
  else if (L > mid)
    return query(node[rt].r, mid + 1, r, L, R);
  else {
    int a = query(node[rt].l, l, mid, L, mid);
    int b = query(node[rt].r, mid + 1, r, mid + 1, R);
    return min(a, b);
  }
}
inline int read() {
  int k = 0;
  char f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  return k * f;
}
int main() {
  int s;
  memset(head, -1, sizeof head);
  cin >> n >> s;
  for (int i = 1; i <= n; i++) poi[i].w = read(), a[i] = i;
  for (int i = 1; i < n; i++) {
    int u, v;
    u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  dfs(s, 0);
  sort(a + 1, a + 1 + n, cmp);
  node[0].m = INF;
  for (int i = 1; i <= n; i++) {
    root[i] = root[i - 1];
    int idx = a[i];
    int p = poi[idx].dfn;
    int w = poi[idx].w;
    update(root[i], 1, n, p, w);
  }
  int m;
  cin >> m;
  int ans = 0;
  while (m--) {
    int x, k;
    x = read(), k = read();
    x = (x + ans) % n + 1;
    k = (k + ans) % n;
    int dep = poi[x].dep + k;
    int l = poi[x].dfn, r = poi[x].col;
    int p = bin(dep);
    ans = query(root[p], 1, n, l, r);
    printf("%d\n", ans);
  }
  return 0;
}
