#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const long long N = 1e5 + 5;
struct node {
  long long v;
  node* left;
  node* right;
} ns[N * 20];
long long cnt = 0;
node* create() {
  (ns + cnt)->v = INF;
  (ns + cnt)->left = ns;
  (ns + cnt)->right = ns;
  return (ns + cnt++);
}
long long query(node* v, long long tl, long long tr, long long l, long long r) {
  if (l > tr || r < tl || v == ns) {
    return INF;
  }
  if (l <= tl && tr <= r) {
    return v->v;
  }
  long long tm = (tl + tr) / 2;
  return min(query(v->left, tl, tm, l, r), query(v->right, tm + 1, tr, l, r));
}
node* update(node* v, long long tl, long long tr, long long id, long long val) {
  if (id < tl || id > tr) {
    return v;
  }
  node* ret = create();
  if (tl == tr) {
    ret->v = val;
    return ret;
  }
  long long tm = (tl + tr) / 2;
  ret->left = update(v->left, tl, tm, id, val);
  ret->right = update(v->right, tm + 1, tr, id, val);
  ret->v = min(ret->left->v, ret->right->v);
  return ret;
}
long long a[N];
long long dep[N];
long long st[N], et[N], tim = 0;
vector<long long> v[N], d[N];
void dfs(long long z, long long p = 0) {
  dep[z] = dep[p] + 1;
  d[dep[z]].push_back(z);
  st[z] = tim++;
  for (long long x : v[z]) {
    if (x == p) continue;
    dfs(x, z);
  }
  et[z] = tim;
}
node* version[N];
void solve() {
  long long n, r;
  cin >> n >> r;
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(r);
  version[0] = create();
  for (long long i = 1; i < n + 1; i++) {
    version[i] = version[i - 1];
    for (long long x : d[i]) {
      version[i] = update(version[i], 0, n + 4, st[x], a[x]);
    }
  }
  long long m;
  cin >> m;
  long long last = 0;
  for (long long i = 0; i < m; i++) {
    long long p, q;
    cin >> p >> q;
    long long x = (p + last) % n + 1;
    long long k = (q + last) % n;
    long long ver = min(dep[x] + k, n);
    last = query(version[ver], 0, n + 4, st[x], et[x] - 1);
    cout << last << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
