#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3")
using namespace std;
void read(int &x) {
  x = 0;
  int c = getchar();
  while (c <= 32) c = getchar();
  while (c > 32) {
    x = (x << 3) + (x << 1) + (c & 15);
    c = getchar();
  }
}
void write(int x) {
  if (x >= 10) write(x / 10);
  putchar(x % 10 + 48);
}
const int Siz = 1e7;
int lson[Siz], rson[Siz], mn[Siz], r[Siz], cnt;
int min(int a, int b) { return a < b ? a : b; }
int clone(int x) {
  int i = ++cnt;
  mn[i] = mn[x];
  lson[i] = lson[x];
  rson[i] = rson[x];
  return i;
}
void ins(int &i, int a, int b, int x, int v) {
  if (!i)
    i = ++cnt;
  else
    i = clone(i);
  if (a + 1 == b) {
    mn[i] = v;
    return;
  }
  int m = (a + b) >> 1;
  if (x < m)
    ins(lson[i], a, m, x, v);
  else
    ins(rson[i], m, b, x, v);
  mn[i] = 1e9;
  if (lson[i]) mn[i] = min(mn[i], mn[lson[i]]);
  if (rson[i]) mn[i] = min(mn[i], mn[rson[i]]);
}
int qry(int i, int a, int b, int l, int r) {
  if (!i) return 1e9;
  if (l <= a && b <= r) {
    return mn[i];
  }
  int ans = 1e9;
  int m = (a + b) >> 1;
  if (l < m) ans = min(ans, qry(lson[i], a, m, l, r));
  if (r > m) ans = min(ans, qry(rson[i], m, b, l, r));
  return ans;
}
const int N = 1e5 + 5;
int n, rt;
int c[N];
int head[N], nex[N << 1], to[N << 1], tot;
void add_edge(int u, int v) {
  to[tot] = v;
  nex[tot] = head[u];
  head[u] = tot++;
}
int dep[N], dfn[N], siz[N], tme;
void dfs(int u, int p) {
  if (~p) dep[u] = dep[p] + 1;
  siz[u] = 1;
  dfn[u] = tme++;
  for (int e = head[u]; ~e; e = nex[e]) {
    int v = to[e];
    if (v != p) {
      dfs(v, u);
      siz[u] += siz[v];
    }
  }
}
int id[N], lst[N];
bool comp(int a, int b) { return dep[a] < dep[b]; }
int main() {
  read(n);
  read(rt);
  --rt;
  for (int i = 0; i < n; ++i) read(c[i]);
  for (int i = 0; i < n; ++i) head[i] = -1;
  for (int i = 1; i < n; ++i) {
    int u, v;
    read(u);
    read(v);
    --u;
    --v;
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(rt, -1);
  for (int i = 0; i < n; ++i) id[i] = i;
  std ::sort(id, id + n, comp);
  int mxdep = 0;
  for (int i = 0; i < n; ++i) {
    if (i) r[i] = r[i - 1];
    ins(r[i], 0, tme, dfn[id[i]], c[id[i]]);
    lst[dep[id[i]]] = i;
    mxdep = dep[id[i]];
  }
  int q, lstans = 0;
  read(q);
  while (q--) {
    int p, q;
    read(p);
    read(q);
    (p += lstans) %= n;
    (q += lstans) %= n;
    int lim = min(dep[p] + q, mxdep);
    write(lstans = qry(r[lst[lim]], 0, tme, dfn[p], dfn[p] + siz[p]));
    putchar(10);
  }
  return 0;
}
