#include <bits/stdc++.h>
using namespace std;
char buff[(int)2e6 + 17];
const long long inf = (long long)1e9 + 7ll;
const int maxn = (int)1e6 + 17;
struct segtree {
  int n;
  vector<int> T;
  segtree() {}
  segtree(int n) : n(n) { T.resize(4 * n, inf); }
  void update(int i, int x, int v, int l, int r) {
    if (l == r)
      T[v] = x;
    else {
      int m = (l + r) / 2;
      if (i <= m)
        update(i, x, 2 * v, l, m);
      else
        update(i, x, 2 * v + 1, m + 1, r);
      T[v] = min(T[2 * v], T[2 * v + 1]);
    }
  }
  int get(int lq, int rq, int v, int l, int r) {
    if (r < lq || l > rq) return inf;
    if (lq <= l && r <= rq) return T[v];
    int m = (l + r) / 2;
    return min(get(lq, rq, 2 * v, l, m), get(lq, rq, 2 * v + 1, m + 1, r));
  }
  void update(int i, int x) { update(i, x, 1, 0, n - 1); }
  int get(int lq, int rq) { return get(lq, rq, 1, 0, n - 1); }
};
int a[maxn], vert[maxn], tin[maxn], tout[maxn], H[maxn];
vector<int> lvl[maxn], g[maxn];
struct segtree2 {
  int n;
  vector<segtree> T;
  vector<vector<int> > vec;
  segtree2() {}
  segtree2(int n) : n(n) { T.resize(4 * n), vec.resize(4 * n); }
  void build(int v, int l, int r) {
    if (l == r) {
      vec[v] = lvl[l];
      T[v] = segtree(static_cast<int>(vec[v].size()));
      for (int i = 0; i < static_cast<int>(vec[v].size()); ++i)
        T[v].update(i, a[vert[lvl[l][i]]]);
      return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    vec[v] = vec[2 * v];
    vec[v].insert(vec[v].end(), vec[2 * v + 1].begin(), vec[2 * v + 1].end());
    sort(vec[v].begin(), vec[v].end());
    T[v] = segtree(static_cast<int>(vec[v].size()));
    for (int i = 0; i < static_cast<int>(vec[v].size()); ++i)
      T[v].update(i, a[vert[vec[v][i]]]);
  }
  int get(int lx, int rx, int ly, int ry, int v, int l, int r) {
    if (r < lx || l > rx) return inf;
    if (lx <= l && r <= rx) {
      int res = inf;
      int lq = lower_bound(vec[v].begin(), vec[v].end(), ly) - vec[v].begin();
      int rq =
          upper_bound(vec[v].begin(), vec[v].end(), ry) - vec[v].begin() - 1;
      if (lq <= rq) res = T[v].get(lq, rq);
      return res;
    }
    int m = (l + r) / 2;
    return min(get(lx, rx, ly, ry, 2 * v, l, m),
               get(lx, rx, ly, ry, 2 * v + 1, m + 1, r));
  }
  int get(int lx, int rx, int ly, int ry) {
    return get(lx, rx, ly, ry, 1, 0, n - 1);
  }
};
int n, r, q, tt;
bool read() {
  if (scanf("%d %d", &n, &r) != 2) return false;
  --r;
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  scanf("%d", &q);
  return true;
}
void dfs(int v, int h = 0, int pr = -1) {
  tin[v] = tt++;
  vert[tin[v]] = v;
  H[v] = h;
  lvl[h].push_back(tin[v]);
  for (auto to : g[v])
    if (to != pr) dfs(to, h + 1, v);
  tout[v] = tt - 1;
}
void solve() {
  dfs(r);
  segtree2 T = segtree2(n);
  T.build(1, 0, n - 1);
  int last = 0;
  for (int i = 0; i < q; ++i) {
    int P, Q;
    scanf("%d %d", &P, &Q);
    int v = (P + last) % n;
    int k = (Q + last) % n;
    printf("%d\n", last = T.get(H[v], min(n - 1, H[v] + k), tin[v], tout[v]));
  }
}
int main() {
  while (read()) solve();
  return 0;
}
