#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4, sz = 320;
int n, r, a[N], in[N], out[N], d[N];
vector<int> g[N];
vector<pair<int, int> > v, tree[4 * N];
void dfs(int node, int parent = -1, int depth = 0) {
  d[node] = depth;
  in[node] = v.size();
  v.push_back({depth, a[node]});
  for (auto child : g[node]) {
    if (child == parent) continue;
    dfs(child, node, depth + 1);
  }
  out[node] = v.size() - 1;
}
void build(int node, int l, int r) {
  if (l == r) {
    tree[node].push_back(v[l]);
    return;
  }
  int md = (l + r) >> 1;
  build(node << 1, l, md);
  build(node << 1 | 1, md + 1, r);
  merge(tree[node << 1].begin(), tree[node << 1].end(),
        tree[node << 1 | 1].begin(), tree[node << 1 | 1].end(),
        back_inserter(tree[node]));
  int mn = 2e9;
  for (auto &it : tree[node]) mn = min(mn, it.second), it.second = mn;
}
int query(int node, int l, int r, int i, int j, int val) {
  if (i > r || j < l || i > j) return 2e9;
  if (l >= i && r <= j) {
    auto it = upper_bound(tree[node].begin(), tree[node].end(),
                          make_pair(val, (int)2e9));
    if (it == tree[node].begin()) return 2e9;
    it--;
    return it->second;
  }
  int md = (l + r) >> 1;
  return min(query(node << 1, l, md, i, j, val),
             query(node << 1 | 1, md + 1, r, i, j, val));
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> r;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(r);
  build(1, 0, v.size() - 1);
  int q;
  cin >> q;
  int last = 0;
  while (q--) {
    int p, q;
    cin >> p >> q;
    int x = (p + last) % n + 1;
    int k = (q + last) % n;
    last = query(1, 0, v.size() - 1, in[x], out[x], k + d[x]);
    cout << last << "\n";
  }
  return 0;
}
