#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using matrix = vector<vector<long long>>;
const int INF = 1e9 + 1;
struct node {
  int val;
  node *l, *r;
  node() : val(INF), l(nullptr), r(nullptr){};
};
const int MAXN = 1e5 + 100;
int arr[MAXN];
int tin[MAXN], tout[MAXN], timer = 0;
int d[MAXN];
vector<int> g[MAXN], dep[MAXN];
node *T[MAXN];
void build(node *&root, int tl, int tr) {
  if (tl + 1 == tr) {
    return;
  }
  root->l = new node(), root->r = new node();
  int tm = (tl + tr) >> 1;
  build(root->l, tl, tm);
  build(root->r, tm, tr);
}
void update(node *&prev, node *&root, int tl, int tr, int pos, int value) {
  if (tl + 1 == tr) {
    root->val = value;
    return;
  }
  int tm = (tl + tr) >> 1;
  if (pos < tm) {
    root->l = new node(), root->r = prev->r;
    update(prev->l, root->l, tl, tm, pos, value);
  } else {
    root->l = prev->l, root->r = new node();
    update(prev->r, root->r, tm, tr, pos, value);
  }
  root->val = min(root->l->val, root->r->val);
}
int get(node *&root, int tl, int tr, int l, int r) {
  if (tl >= r || tr <= l) {
    return INF;
  }
  if (tl >= l && tr <= r) {
    return root->val;
  }
  int tm = (tl + tr) >> 1;
  int a = get(root->l, tl, tm, l, r);
  int b = get(root->r, tm, tr, l, r);
  return min(a, b);
}
void dfs(int u, int p) {
  tin[u] = timer++;
  dep[d[u]].push_back(u);
  for (int to : g[u]) {
    if (to == p) {
      continue;
    }
    d[to] = d[u] + 1;
    dfs(to, u);
  }
  tout[u] = timer;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, root;
  cin >> n >> root;
  root--;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  d[root] = 1;
  dfs(root, -1);
  for (int i = 0; i <= n; ++i) {
    T[i] = new node();
  }
  build(T[0], 0, n);
  for (int i = 1; i <= n; ++i) {
    node *prev = T[i - 1];
    for (int j : dep[i]) {
      node *cur = new node();
      update(prev, cur, 0, n, tin[j], arr[j]);
      prev = cur;
    }
    T[i] = prev;
  }
  int last = 0;
  int q;
  cin >> q;
  while (q--) {
    int P, Q;
    cin >> P >> Q;
    int x = (P + last) % n;
    int k = (Q + last) % n;
    int need = min(n, d[x] + k);
    last = get(T[need], 0, n, tin[x], tout[x]);
    cout << last << '\n';
  }
}
