#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int MAXN = 100005;
constexpr int INF = 1e9 + 7;
int n, r;
vector<int> tree[MAXN];
int val[MAXN];
int depth[MAXN];
int tin[MAXN], rtin[MAXN], tout[MAXN];
int timer = 0;
void dfs(int u, int par = -1) {
  tin[u] = timer++;
  rtin[tin[u]] = u;
  for (int v : tree[u]) {
    if (v == par) continue;
    depth[v] = depth[u] + 1;
    dfs(v, u);
  }
  tout[u] = timer;
}
vector<int> seg[4 * MAXN];
pair<int, int> range[4 * MAXN];
bool cmp(const int& a, const int& b) {
  return depth[a] < depth[b] or (depth[a] == depth[b] and val[a] < val[b]);
}
void build(int node, int l, int r) {
  if (l == r) {
    seg[node].push_back(rtin[l]);
  } else {
    int mid = (l + r) >> 1;
    build(2 * node, l, mid);
    build(2 * node + 1, mid + 1, r);
    merge(begin(seg[2 * node]), end(seg[2 * node]), begin(seg[2 * node + 1]),
          end(seg[2 * node + 1]), back_inserter(seg[node]), cmp);
  }
}
int query(const vector<int>& f_tree, int ind) {
  int res = INF;
  for (int x = ind + 1; x; x -= (x & -x)) {
    res = min(res, f_tree[x]);
  }
  return res;
}
void update(vector<int>& f_tree, int ind, int vvv) {
  for (int x = ind + 1; x < f_tree.size(); x += (x & -x)) {
    f_tree[x] = min(f_tree[x], vvv);
  }
}
void process(int node) {
  if (seg[node].size() > 1) {
    process(2 * node);
    process(2 * node + 1);
  }
  range[node] = {depth[seg[node][0]], depth[seg[node].back()]};
  vector<int> f_tree(range[node].second - range[node].first + 2, INF);
  for (int u : seg[node]) {
    update(f_tree, depth[u] - range[node].first, val[u]);
  }
  seg[node] = f_tree;
}
int query(int node, int l, int r, int ql, int qr, int k) {
  if (l == ql and r == qr) {
    if (k < range[node].first) return INF;
    if (k - range[node].first + 1 >= seg[node].size())
      return query(seg[node], seg[node].size() - 2);
    return query(seg[node], k - range[node].first);
  }
  int res = INF;
  int mid = (l + r) >> 1;
  if (ql <= mid) {
    res = min(res, query(2 * node, l, mid, ql, min(mid, qr), k));
  }
  if (mid + 1 <= qr) {
    res = min(res, query(2 * node + 1, mid + 1, r, max(mid + 1, ql), qr, k));
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  scanf("%d %d", &n, &r);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", val + i);
  }
  int u, v;
  for (int i = 1; i < n; ++i) {
    scanf("%d %d", &u, &v);
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  depth[r] = 0;
  dfs(r);
  build(1, 0, n - 1);
  process(1);
  int m;
  scanf("%d", &m);
  int last = 0;
  int p, q;
  while (m-- > 0) {
    scanf("%d %d", &p, &q);
    int x = ((p + last) % n) + 1;
    int k = (q + last) % n;
    last = query(1, 0, n - 1, tin[x], tout[x] - 1, depth[x] + k);
    printf("%d\n", last);
  }
  return 0;
}
