#include <bits/stdc++.h>
using namespace std;
inline int readi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int MAXN = 1e5 + 5;
int n, r, m;
int a[MAXN], dep[MAXN];
vector<int> adj[MAXN];
int tl[MAXN], tr[MAXN], inv[MAXN], Tm;
void dfs(int cur, int p = -1) {
  if (p != -1) dep[cur] = dep[p] + 1;
  tl[cur] = ++Tm;
  inv[Tm] = cur;
  for (int v : adj[cur])
    if (v != p) {
      dfs(v, cur);
    }
  tr[cur] = Tm;
}
vector<pair<int, int> > t[4 * MAXN];
vector<int> pre[4 * MAXN];
void pull(int x) {
  merge(t[x << 1].begin(), t[x << 1].end(), t[x << 1 | 1].begin(),
        t[x << 1 | 1].end(), back_inserter(t[x]));
  pre[x].push_back(t[x][0].second);
  for (int i = 1; i < ((int)(t[x]).size()); i++) {
    pre[x].push_back(min(pre[x].back(), t[x][i].second));
  }
}
void build(int x, int l, int r) {
  if (l == r) {
    t[x].push_back({dep[inv[l]], a[inv[l]]});
    pre[x].push_back(t[x][0].second);
  } else {
    int mid = l + r >> 1;
    build(x << 1, l, mid);
    build(x << 1 | 1, mid + 1, r);
    pull(x);
  }
}
int get(int x, int d) {
  int id = lower_bound(t[x].begin(), t[x].end(), make_pair(d + 1, 0)) -
           t[x].begin() - 1;
  if (id == -1) return 2000000000;
  return pre[x][lower_bound(t[x].begin(), t[x].end(), make_pair(d + 1, 0)) -
                t[x].begin() - 1];
}
int query(int x, int l, int r, int ql, int qr, int d) {
  if (r < ql || l > qr || l > r) return 2000000000;
  if (l >= ql && r <= qr) return get(x, d);
  int mid = l + r >> 1;
  return min(query(x << 1, l, mid, ql, qr, d),
             query(x << 1 | 1, mid + 1, r, ql, qr, d));
}
int main() {
  n = readi(), r = readi();
  for (int i = 1; i <= n; i++) a[i] = readi();
  for (int i = 1; i < n; i++) {
    int x = readi(), y = readi();
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(r);
  build(1, 1, n);
  m = readi();
  int last = 0;
  while (m--) {
    int x = (readi() + last) % n + 1;
    int k = (readi() + last) % n;
    last = query(1, 1, n, tl[x], tr[x], dep[x] + k);
    printf("%d\n", last);
  }
  return 0;
}
