#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int inf = 1e9 + 7;
long long powmod(long long x, long long y) {
  long long t;
  for (t = 1; y; y >>= 1, x = x * x % mod)
    if (y & 1) t = t * x % mod;
  return t;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int n, r, m, x, y, maxv, last;
int a[maxn], v[maxn];
int pl[maxn], pr[maxn], dep[maxn];
vector<int> g[maxn];
int rt[maxn], ls[maxn * 20], rs[maxn * 20], sum[maxn * 20], tot = 0;
void build(int& o, int l, int r) {
  o = ++tot;
  sum[o] = inf;
  if (l == r) return;
  int mid = l + r >> 1;
  build(ls[o], l, mid);
  build(rs[o], mid + 1, r);
}
void update(int& o, int last, int l, int r, int p, int v) {
  o = ++tot;
  ls[o] = ls[last], rs[o] = rs[last];
  if (l == r) {
    sum[o] = v;
    return;
  }
  int mid = l + r >> 1;
  if (p <= mid)
    update(ls[o], ls[o], l, mid, p, v);
  else
    update(rs[o], rs[o], mid + 1, r, p, v);
  sum[o] = min(sum[ls[o]], sum[rs[o]]);
  return;
}
int query(int o, int l, int r, int L, int R) {
  if (L <= l && r <= R) return sum[o];
  int mid = l + r >> 1, ans = inf;
  if (L <= mid) ans = min(ans, query(ls[o], l, mid, L, R));
  if (mid < R) ans = min(ans, query(rs[o], mid + 1, r, L, R));
  return ans;
}
void dfs(int u, int pre) {
  pl[u] = ++tot;
  dep[u] = dep[pre] + 1;
  maxv = max(maxv, dep[u]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == pre) continue;
    dfs(v, u);
  }
  pr[u] = tot;
}
int vis[maxn], mp[maxn];
void bfs() {
  int tmp = 0;
  queue<int> p;
  p.push(r);
  while (!p.empty()) {
    int tp = p.front();
    p.pop();
    if (vis[tp])
      continue;
    else
      vis[tp] = 1;
    update(rt[tmp + 1], rt[tmp], 1, 2 * n, pl[tp], a[tp]);
    mp[dep[tp]] = ++tmp;
    for (int i = 0; i < g[tp].size(); i++) {
      if (vis[g[tp][i]]) continue;
      p.push(g[tp][i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> r;
  for (int(i) = (1); (i) < (n + 1); (i)++) cin >> a[i];
  for (int(i) = (1); (i) < (n); (i)++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(r, 0);
  tot = 0;
  build(rt[0], 1, n << 1);
  bfs();
  cin >> m;
  for (int(i) = (0); (i) < (m); (i)++) {
    cin >> x >> y;
    x = (x + last) % n + 1, y = (y + last) % n;
    last = query(rt[mp[min(dep[x] + y, maxv)]], 1, n << 1, pl[x], pr[x]);
    cout << last << '\n';
  }
  return 0;
}
