#include <bits/stdc++.h>
using namespace std;
int n, root, m;
int a[100100];
int h[100100];
vector<int> g[100100];
int arr[200100];
int N, tin[100100], tout[100100];
vector<pair<int, int> > t[200100 * 4];
void dfs(int v, int par = -1, int len = 0) {
  h[v] = len;
  tin[v] = ++N;
  arr[N] = v;
  for (int to : g[v]) {
    if (to != par) {
      dfs(to, v, len + 1);
    }
  }
  tout[v] = ++N;
  arr[N] = v;
}
void build(int v, int l, int r) {
  if (l == r) {
    int node = arr[l];
    t[v].push_back(make_pair(h[node], a[node]));
    return;
  }
  int mid = (l + r) >> 1;
  build(v + v, l, mid), build(v + v + 1, mid + 1, r);
  merge((t[v + v]).begin(), (t[v + v]).end(), (t[v + v + 1]).begin(),
        (t[v + v + 1]).end(), back_inserter(t[v]));
  for (int i = 1; i < ((int)(t[v]).size()); ++i) {
    t[v][i].second = min(t[v][i - 1].second, t[v][i].second);
  }
}
int get(int v, int l, int r, int L, int R, int k) {
  if (r < L || R < l) return 2e9;
  if (L <= l && r <= R) {
    int lf = 0, rg = ((int)(t[v]).size()) - 1, i = -1;
    while (lf <= rg) {
      int avg = (lf + rg) >> 1;
      if (t[v][avg].first <= k)
        i = avg, lf = avg + 1;
      else
        rg = avg - 1;
    }
    return i == -1 ? 2e9 : t[v][i].second;
  }
  int mid = (l + r) >> 1;
  return min(get(v + v, l, mid, L, R, k), get(v + v + 1, mid + 1, r, L, R, 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];
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(root);
  build(1, 1, N);
  cin >> m;
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    int p, q;
    cin >> p >> q;
    int x = (p + ans) % n + 1;
    int k = (q + ans) % n;
    ans = get(1, 1, N, tin[x], tout[x], h[x] + k);
    cout << ans << "\n";
  }
  return 0;
}
