#include <bits/stdc++.h>
using namespace std;
inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
  register T sum(0), fg(1);
  register char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fg = -1;
  for (; isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
  return sum * fg;
}
const int MAXN = (int)1e5;
int n, r;
int A[MAXN + 5];
vector<int> adj[MAXN + 5];
inline void input() {
  n = read<int>(), r = read<int>();
  for (int i = 1; i <= n; ++i) A[i] = read<int>();
  for (int i = 1; i < n; ++i) {
    int u = read<int>(), v = read<int>();
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}
int dfn[MAXN + 5], ed[MAXN + 5], dfn_cur = 0, dep[MAXN + 5];
vector<int> dep_set[MAXN + 5];
inline void dfs(int u, int fa) {
  dep_set[dep[u] = dep[fa] + 1].push_back(u);
  dfn[u] = ++dfn_cur;
  for (auto v : adj[u])
    if (v != fa) dfs(v, u);
  ed[u] = dfn_cur;
}
namespace SEGT {
const int MAX_NODE = 30 * MAXN;
int lc[MAX_NODE + 5], rc[MAX_NODE + 5], cnt = 0;
int mn[MAX_NODE + 5];
inline int update(int u, int l, int r, int pos, int val) {
  int v = ++cnt;
  mn[v] = u ? min(mn[u], val) : val;
  lc[v] = lc[u], rc[v] = rc[u];
  if (l == r) return v;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    lc[v] = update(lc[u], l, mid, pos, val);
  else
    rc[v] = update(rc[u], mid + 1, r, pos, val);
  return v;
}
inline int query(int u, int l, int r, int ql, int qr) {
  if (!u) return INT_MAX;
  if (ql <= l && r <= qr) return mn[u];
  int mid = (l + r) >> 1, res = INT_MAX;
  if (ql <= mid) chkmin(res, query(lc[u], l, mid, ql, qr));
  if (mid < qr) chkmin(res, query(rc[u], mid + 1, r, ql, qr));
  return res;
}
}  // namespace SEGT
inline void solve() {
  dfs(r, 0);
  static int pos[MAXN + 5], cnt = 0;
  static int root[MAXN + 5];
  for (int i = 1; i <= n; ++i) {
    for (auto u : dep_set[i])
      ++cnt, root[cnt] = SEGT::update(root[cnt - 1], 1, n, dfn[u], A[u]);
    pos[i] = cnt;
  }
  for (int m = read<int>(), lastans = 0; m--;) {
    int u = (read<int>() + lastans) % n + 1;
    int k = (read<int>() + lastans) % n;
    printf("%d\n", lastans = SEGT::query(root[pos[min(dep[u] + k, n)]], 1, n,
                                         dfn[u], ed[u]));
  }
}
int main() {
  input();
  solve();
  return 0;
}
