#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 1e5 + 5;
bool vis[N];
vector<pair<int, int>> flat;
vector<vector<int>> edges(N);
vector<pair<int, int>> seg[N << 2];
long long root, n, m, k, p, last, a[N], l[N], r[N], d[N];
void build(int s, int e, int idx) {
  if (s == e) {
    seg[idx].push_back(flat[s]);
    return;
  }
  int mid = (s + e) / 2;
  build(s, mid, 2 * idx + 1);
  build(mid + 1, e, 2 * idx + 2);
  merge(seg[2 * idx + 1].begin(), seg[2 * idx + 1].end(),
        seg[2 * idx + 2].begin(), seg[2 * idx + 2].end(),
        back_inserter(seg[idx]));
  for (int i = 1; i < seg[idx].size(); i++)
    seg[idx][i].second = min(seg[idx][i].second, seg[idx][i - 1].second);
}
int get_ans(int l, int r, int s, int e, int idx, int lvl) {
  if (l > e || s > r) return 2e9;
  if (s >= l && e <= r) {
    auto it =
        upper_bound(seg[idx].begin(), seg[idx].end(), make_pair(lvl, (int)2e9));
    if (it == seg[idx].begin()) return 2e9;
    it--;
    return it->second;
  }
  int mid = (s + e) / 2;
  return min(get_ans(l, r, s, mid, 2 * idx + 1, lvl),
             get_ans(l, r, mid + 1, e, 2 * idx + 2, lvl));
}
void dfs(int node, int lvl) {
  vis[node] = 1;
  d[node] = lvl;
  l[node] = flat.size();
  flat.push_back({lvl, a[node]});
  for (auto i : edges[node])
    if (!vis[i]) dfs(i, lvl + 1);
  r[node] = flat.size() - 1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> root;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    cin >> p >> k;
    edges[p].push_back(k);
    edges[k].push_back(p);
  }
  dfs(root, 0);
  build(0, n - 1, 0);
  cin >> m;
  while (m--) {
    cin >> p >> k;
    p = (p + last) % n + 1;
    k = (k + last) % n;
    last = get_ans(l[p], r[p], 0, n - 1, 0, d[p] + k);
    cout << last << endl;
  }
  return 0;
}
