#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T bpow(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int ts, kk = 1;
int n, m, root;
int a[100005];
vector<int> al[100005];
map<int, int> tr[100005 * 4];
int st[100005], ft[100005], dfstm;
int ver[100005];
int ds[100005];
void dfs(int u, int par, int d) {
  int i;
  ver[dfstm] = u;
  st[u] = dfstm++;
  ds[u] = d;
  for (i = 0; i < al[u].size(); i++) {
    int v = al[u][i];
    if (v == par) continue;
    dfs(v, u, d + 1);
  }
  ft[u] = dfstm;
}
void bld(int i, int s, int e) {
  if (s == e) {
    tr[i][ds[ver[s]]] = a[ver[s]];
    return;
  }
  bld(((i << 1) + 1), s, ((s + e) >> 1));
  bld((((i << 1) + 1) + 1), ((s + e) >> 1) + 1, e);
  auto lt = tr[((i << 1) + 1)].begin();
  auto rt = tr[(((i << 1) + 1) + 1)].begin();
  int mx = min(lt->first, rt->first);
  int qs = 1000000007LL;
  for (; lt != tr[((i << 1) + 1)].end() && rt != tr[(((i << 1) + 1) + 1)].end();
       mx++) {
    if (lt->first == mx) qs = min(qs, lt->second), lt++;
    if (rt->first == mx) qs = min(qs, rt->second), rt++;
    tr[i][mx] = qs;
  }
  for (; lt != tr[((i << 1) + 1)].end(); mx++) {
    if (lt->first == mx) qs = min(qs, lt->second), lt++;
    tr[i][mx] = qs;
  }
  for (; rt != tr[(((i << 1) + 1) + 1)].end(); mx++) {
    if (rt->first == mx) qs = min(qs, rt->second), rt++;
    tr[i][mx] = qs;
  }
}
int qry(int i, int s, int e, int st, int ed, int k) {
  if (k < tr[i].begin()->first) return 1000000007LL;
  if (st <= s && e <= ed) {
    auto x = tr[i].lower_bound(k);
    if (x == tr[i].end()) return tr[i].rbegin()->second;
    return x->second;
  }
  if (ed <= ((s + e) >> 1))
    return qry(((i << 1) + 1), s, ((s + e) >> 1), st, ed, k);
  if (((s + e) >> 1) < st)
    return qry((((i << 1) + 1) + 1), ((s + e) >> 1) + 1, e, st, ed, k);
  return min(qry(((i << 1) + 1), s, ((s + e) >> 1), st, ed, k),
             qry((((i << 1) + 1) + 1), ((s + e) >> 1) + 1, e, st, ed, k));
}
int main() {
  int t, i, j, k;
  scanf("%d%d", &n, &root);
  for (i = 1; i < n + 1; i++) scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &j, &k);
    al[j].push_back(k);
    al[k].push_back(j);
  }
  dfs(root, -1, 0);
  assert(dfstm == n);
  bld(0, 0, dfstm - 1);
  scanf("%d", &ts);
  int ans = 0;
  while (ts--) {
    scanf("%d%d", &j, &k);
    j = (j + ans) % n + 1;
    k = (k + ans) % n;
    ans = qry(0, 0, dfstm - 1, st[j], ft[j] - 1, ds[j] + k);
    printf("%d\n", ans);
  }
  return 0;
}
