#include <bits/stdc++.h>
using namespace std;
vector<int> g[100005];
vector<int> dep[100005];
int a[100005];
int n, r;
int dfs_time;
int In[100005];
int Out[100005];
int pos[100005];
int dis[100005];
int Max;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
struct node {
  int l, r;
  int Min;
} T[100005 << 6];
int ver[100005];
int tot;
void PushUp(int rt) { T[rt].Min = min(T[T[rt].l].Min, T[T[rt].r].Min); }
int BuildTree(int l, int r) {
  int rt = (++tot);
  T[rt].Min = 0x7f7f7f7f;
  if (l == r) return rt;
  int m = (l + r) >> 1;
  T[rt].l = BuildTree(l, m);
  T[rt].r = BuildTree(m + 1, r);
  return rt;
}
int Update(int pre, int l, int r, int x) {
  int rt = (++tot);
  T[rt] = T[pre];
  if (l == r) {
    T[rt].Min = a[pos[x]];
    return rt;
  }
  int m = (l + r) >> 1;
  if (x <= m)
    T[rt].l = Update(T[pre].l, l, m, x);
  else
    T[rt].r = Update(T[pre].r, m + 1, r, x);
  PushUp(rt);
  return rt;
}
void debug(int rt, int l, int r) {
  cout << l << " " << r << endl;
  cout << T[rt].Min << endl;
  if (l == r) return;
  int m = (l + r) >> 1;
  debug(T[rt].l, l, m);
  debug(T[rt].r, m + 1, r);
}
int Query(int rt, int L, int R, int l, int r) {
  if (L <= l && R >= r) return T[rt].Min;
  int ans = 0x7f7f7f7f;
  int m = (l + r) >> 1;
  if (L <= m) ans = min(ans, Query(T[rt].l, L, R, l, m));
  if (R > m) ans = min(ans, Query(T[rt].r, L, R, m + 1, r));
  return ans;
}
void DFS(int u, int fa, int depth) {
  Max = max(Max, depth);
  dis[u] = depth;
  dep[depth].push_back(u);
  pos[dfs_time] = u;
  In[u] = dfs_time++;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == fa) continue;
    DFS(v, u, depth + 1);
  }
  Out[u] = dfs_time - 1;
}
int main() {
  n = read();
  r = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    u = read();
    v = read();
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs_time = 1;
  DFS(r, -1, 1);
  ver[0] = BuildTree(1, n);
  for (int i = 1; i <= Max; i++) {
    ver[i] = ver[i - 1];
    for (int j = 0; j < dep[i].size(); j++) {
      int u = dep[i][j];
      ver[i] = Update(ver[i], 1, n, In[u]);
    }
  }
  int m;
  m = read();
  int las = 0;
  while (m--) {
    int p, q;
    p = read();
    q = read();
    int x = ((p + las) % n) + 1;
    int k = (q + las) % n;
    int tag = min(Max, dis[x] + k);
    int ans = Query(ver[tag], In[x], Out[x], 1, n);
    write(ans);
    putchar('\n');
    las = ans;
  }
  return 0;
}
