#include <bits/stdc++.h>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
using namespace std;
vector<int> g[100100];
vector<int> t[4 * 100100];
vector<int> L[4 * 100100];
vector<int> val[4 * 100100];
int tin[100100];
int tout[100100];
int a[100100];
int timer = 0;
int n;
int V[100100];
int lev[100100];
int r;
void dfs(int v, int p) {
  V[timer] = v;
  lev[v] = lev[p] + 1;
  tin[v] = timer++;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    dfs(to, v);
  }
  tout[v] = timer - 1;
}
void build(int v, int l, int r) {
  if (l == r) {
    int D = V[l];
    t[v].push_back(lev[D]);
    val[v].push_back(a[D]);
    return;
  }
  int mid = (l + r) >> 1;
  build(v * 2, l, mid);
  build(v * 2 + 1, mid + 1, r);
  int i = 0, j = 0;
  vector<int>& x = t[v * 2];
  vector<int>& y = t[v * 2 + 1];
  while (i < x.size() && j < y.size()) {
    if (x[i] < y[j]) {
      val[v].push_back(val[v * 2][i]);
      t[v].push_back(x[i]);
      i++;
      L[v].push_back(i);
    } else {
      val[v].push_back(val[v * 2 + 1][j]);
      t[v].push_back(y[j]);
      j++;
      L[v].push_back(i);
    }
  }
  while (i < x.size()) {
    val[v].push_back(val[v * 2][i]);
    t[v].push_back(x[i]);
    i++;
    L[v].push_back(i);
  }
  while (j < y.size()) {
    val[v].push_back(val[v * 2 + 1][j]);
    t[v].push_back(y[j]);
    j++;
    L[v].push_back(i);
  }
  for (int i = 1; i < val[v].size(); i++) {
    val[v][i] = min(val[v][i], val[v][i - 1]);
  }
}
int get(int v, int tl, int tr, int l, int r, int pos) {
  if (l > tr || tl > r || pos == 0) return inf;
  if (l <= tl && tr <= r) {
    return val[v][pos - 1];
  }
  int mid = (tl + tr) >> 1;
  return min(get(v * 2, tl, mid, l, r, L[v][pos - 1]),
             get(v * 2 + 1, mid + 1, tr, l, r, pos - L[v][pos - 1]));
}
inline int nextInt() {
  register int n = 0;
  register char c = getchar();
  while (c == ' ' || c == '\t' || c == '\n') {
    c = getchar();
  }
  while (!(c == ' ' || c == '\t' || c == '\n')) {
    n = n * 10 + c - '0';
    c = getchar();
  }
  return n;
}
void out(int x) {
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
void solve() {
  n = nextInt();
  r = nextInt();
  for (int i = 1; i <= n; i++) {
    a[i] = nextInt();
  }
  for (int i = 1, x, y; i < n; i++) {
    x = nextInt();
    y = nextInt();
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(r, 0);
  build(1, 0, n - 1);
  int m;
  cin >> m;
  int last = 0;
  for (int i = 0, x, y; i < m; i++) {
    x = nextInt();
    y = nextInt();
    x = (x + last) % n + 1;
    y = (y + last) % n;
    int pos = upper_bound(t[1].begin(), t[1].end(), lev[x] + y) - t[1].begin();
    last = get(1, 0, n - 1, tin[x], tout[x], pos);
    out(last);
    putchar('\n');
  }
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
