#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int inf = (1 << 30) - 1;
const int N = (int)1e5 + 5;
int n, m, root, in[N], out[N], T, a[N];
int h[N], c[N], b[N];
vector<int> g[N], ls[4 * N], rs[4 * N], d[4 * N];
vector<pair<int, int> > t[4 * N];
void _merge(int a, int b, int c) {
  t[c].resize(((int)(t[a]).size()) + ((int)(t[b]).size()));
  ls[c].resize(((int)(t[a]).size()) + ((int)(t[b]).size()));
  rs[c].resize(((int)(t[a]).size()) + ((int)(t[b]).size()));
  d[c].resize(((int)(t[a]).size()) + ((int)(t[b]).size()));
  int i = 0, j = 0, k = 0;
  while (i != ((int)(t[a]).size()) || j != ((int)(t[b]).size())) {
    if (i == ((int)(t[a]).size()))
      t[c][k] = t[b][j++];
    else if (j == ((int)(t[b]).size()))
      t[c][k] = t[a][i++];
    else if (t[a][i] <= t[b][j])
      t[c][k] = t[a][i++];
    else
      t[c][k] = t[b][j++];
    ls[c][k] = i - 1;
    rs[c][k] = j - 1;
    k++;
  }
  for (int i = 0; i < ((int)(d[c]).size()); i++) {
    if (i == 0)
      d[c][i] = t[c][i].second;
    else
      d[c][i] = min(d[c][i - 1], t[c][i].second);
  }
}
void build(int v, int l, int r) {
  if (l == r) {
    t[v].push_back(make_pair(b[l], c[l]));
    d[v].push_back(c[l]);
  } else {
    build(v + v, l, ((l + r) >> 1));
    build(v + v + 1, ((l + r) >> 1) + 1, r);
    _merge(v + v, v + v + 1, v);
  }
}
int get(int v, int l, int r, int L, int R, int i) {
  if (r < L || R < l || i == -1) return inf;
  if (L <= l && r <= R) return d[v][i];
  return min(get(v + v, l, ((l + r) >> 1), L, R, ls[v][i]),
             get(v + v + 1, ((l + r) >> 1) + 1, r, L, R, rs[v][i]));
}
void dfs(int v, int pr = 0) {
  h[v] = h[pr] + 1;
  in[v] = ++T;
  b[in[v]] = h[v];
  c[in[v]] = a[v];
  for (int u : g[v]) {
    if (pr != u) dfs(u, v);
  }
  out[v] = T;
}
int main() {
  scanf("%d %d", &n, &root);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(root);
  build(1, 1, n);
  scanf("%d", &m);
  int last = 0;
  for (int i = 1; i <= m; i++) {
    int x, k;
    scanf("%d %d", &x, &k);
    x = (x + last) % n + 1;
    k = (k + last) % n;
    k += h[x];
    int index = (upper_bound((t[1]).begin(), (t[1]).end(), make_pair(k, inf)) -
                 t[1].begin()) -
                1;
    last = get(1, 1, n, in[x], out[x], index);
    printf("%d\n", last);
  }
  return 0;
}
