#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, INF = 0x3f3f3f3f;
struct Segment_tree {
  struct Node {
    vector<pair<int, int> > value;
    vector<int> minv;
  } seg[MAXN << 2];
  void modify(int pos, pair<int, int> value, int left, int right, int x) {
    seg[x].value.push_back(value);
    if (left == right) return;
    int mid = (left + right) / 2;
    if (pos <= mid)
      modify(pos, value, left, mid, x << 1);
    else
      modify(pos, value, mid + 1, right, x << 1 | 1);
  }
  void build(int left, int right, int x) {
    sort(seg[x].value.begin(), seg[x].value.end());
    seg[x].minv.push_back(seg[x].value[0].second);
    for (int i = 1; i < seg[x].value.size(); i++)
      seg[x].minv.push_back(min(seg[x].minv[i - 1], seg[x].value[i].second));
    if (left == right) return;
    int mid = (left + right) / 2;
    build(left, mid, x << 1);
    build(mid + 1, right, x << 1 | 1);
  }
  int query(int depth, int x) {
    if (seg[x].value[0].first > depth) return INF;
    int left = 0, right = seg[x].value.size();
    while (right - left > 1) {
      int mid = (left + right) / 2;
      if (seg[x].value[mid].first > depth)
        right = mid;
      else
        left = mid;
    }
    return seg[x].minv[left];
  }
  int query(int depth, int l, int r, int left, int right, int x) {
    if (l == left && r == right) return query(depth, x);
    int mid = (left + right) / 2;
    if (r <= mid)
      return query(depth, l, r, left, mid, x << 1);
    else if (l > mid)
      return query(depth, l, r, mid + 1, right, x << 1 | 1);
    else
      return min(query(depth, l, mid, left, mid, x << 1),
                 query(depth, mid + 1, r, mid + 1, right, x << 1 | 1));
  }
} tree;
vector<int> edges[MAXN];
int n, m, root, t;
int value[MAXN], depth[MAXN], start[MAXN], over[MAXN];
void dfs(int x, int y, int d) {
  depth[x] = d;
  start[x] = ++t;
  for (auto i : edges[x])
    if (i != y) dfs(i, x, d + 1);
  over[x] = t;
}
int main() {
  scanf("%d%d", &n, &root);
  for (int i = 1; i <= n; i++) scanf("%d", value + i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  dfs(root, 0, 1);
  for (int i = 1; i <= n; i++)
    tree.modify(start[i], make_pair(depth[i], value[i]), 1, n, 1);
  tree.build(1, n, 1);
  scanf("%d", &m);
  int ans = 0;
  while (m--) {
    int x, k;
    scanf("%d%d", &x, &k);
    x = (x + ans) % n + 1;
    k = (k + ans) % n;
    ans = tree.query(depth[x] + k, start[x], over[x], 1, n, 1);
    printf("%d\n", ans);
  }
  return 0;
}
