#include <bits/stdc++.h>
using namespace std;
int cnt, starts[1000005], endd[1000005], tim[1000005], h[1000005], arr[1000005];
vector<int> v[1000005];
vector<pair<int, int> > seg[4000016];
vector<pair<int, int> >::iterator it;
void build(int node, int start, int end) {
  if (start > end) return;
  if (start == end) {
    seg[node].push_back(make_pair(h[tim[start]], arr[tim[start]]));
    return;
  }
  int mid = (start + end) / 2;
  build(node << 1, start, mid);
  build(node << 1 | 1, mid + 1, end);
  seg[node].resize(seg[node << 1].size() + seg[node << 1 | 1].size());
  merge(seg[node << 1].begin(), seg[node << 1].end(),
        seg[node << 1 | 1].begin(), seg[node << 1 | 1].end(),
        seg[node].begin());
  for (int i = 1; i < seg[node].size(); i++) {
    seg[node][i].second = min(seg[node][i].second, seg[node][i - 1].second);
  }
}
int query(int node, int start, int end, int l, int r, int k) {
  if (start > end || r < start || end < l) return 2e9;
  if (l <= start && end <= r) {
    it = upper_bound(seg[node].begin(), seg[node].end(),
                     make_pair(k, 2000000000));
    if (it == seg[node].begin()) return 2000000000;
    it--;
    return (*it).second;
  }
  int mid = (start + end) / 2;
  return min(query(node << 1, start, mid, l, r, k),
             query(node << 1 | 1, mid + 1, end, l, r, k));
}
void dfs(int node, int par, int lev) {
  tim[++cnt] = node;
  starts[node] = cnt;
  h[node] = lev;
  for (int i = 0; i < v[node].size(); i++)
    if (v[node][i] != par) dfs(v[node][i], node, lev + 1);
  endd[node] = cnt;
}
int main() {
  int n, root, last = 0, m, a, b, p, q, x, k;
  scanf("%d%d", &n, &root);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(root, 0, 1);
  build(1, 1, n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &p, &q);
    x = (p + last) % n + 1, k = (q + last) % n;
    printf("%d\n", last = query(1, 1, n, starts[x], endd[x], h[x] + k));
  }
  return 0;
}
