#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m, root, a[100005];
int l[100005], r[100005];
int lvl[100005];
vector<vector<int>> tree;
vector<vector<pair<int, int>>> seg(400005);
vector<pair<int, int>> v;
void dfs(int node, int par) {
  lvl[node] = lvl[par] + 1;
  l[node] = v.size();
  v.push_back({lvl[node], a[node]});
  for (auto &i : tree[node])
    if (i != par) dfs(i, node);
  r[node] = v.size() - 1;
}
void build(int node, int s, int e) {
  if (s == e) {
    seg[node].push_back(v[s]);
    return;
  }
  int mid = s + e >> 1;
  build(node << 1, s, mid);
  build(node << 1 | 1, mid + 1, e);
  merge(seg[node << 1].begin(), seg[node << 1].end(),
        seg[node << 1 | 1].begin(), seg[node << 1 | 1].end(),
        back_inserter(seg[node]));
  for (int i = 1; i < seg[node].size(); i++)
    seg[node][i].second = min(seg[node][i].second, seg[node][i - 1].second);
}
int get(int node, int s, int e, int a, int b, int k) {
  if (s > b || e < a) return 2e9;
  if (a <= s && e <= b) {
    auto it =
        upper_bound(seg[node].begin(), seg[node].end(), make_pair(k, (int)2e9));
    if (it == seg[node].begin()) return 2e9;
    return (--it)->second;
  }
  int mid = s + e >> 1;
  return min(get(node << 1, s, mid, a, b, k),
             get(node << 1 | 1, mid + 1, e, a, b, k));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> root;
  for (int i = 1; i <= n; i++) cin >> a[i];
  tree.resize(n + 5);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  dfs(root, root);
  build(1, 0, n - 1);
  cin >> m;
  int lst = 0;
  while (m--) {
    int x, k;
    cin >> x >> k;
    x = (x + lst) % n + 1;
    k = (k + lst) % n;
    cout << (lst = get(1, 0, n - 1, l[x], r[x], lvl[x] + k)) << '\n';
  }
  return 0;
}
