#include <bits/stdc++.h>
using namespace std;
const int N = 100100, L = 19, INF = (int)1e9 + 5;
int n, a[N];
vector<int> tree[N], layer[N];
int anc[L][N], rmq[L][N], dpt[N], st[N], en[N], rev[N], timer;
void df0(int u = 1, int par = 0, int depth = 1) {
  st[u] = ++timer;
  rev[timer] = u;
  dpt[u] = depth;
  anc[0][u] = par;
  layer[depth].emplace_back(timer);
  for (const int& v : tree[u])
    if (v != par) df0(v, u, depth + 1);
  en[u] = timer;
}
void init_dp() {
  for (int j = 1; j < L; j++)
    for (int i = 1; i <= n; i++) {
      int pops = anc[j - 1][i];
      anc[j][i] = (pops > 0 ? anc[j - 1][pops] : 0);
    }
  for (int i = 1; i <= n; i++) rmq[0][i] = a[i];
  for (int i = 1; i <= n; i++) {
    if (anc[0][i] > 0) {
      int& t = rmq[0][anc[0][i]];
      t = min(t, a[i]);
    }
  }
  for (int j = 1; j < L; j++) {
    for (int i = 1; i <= n; i++) rmq[j][i] = rmq[j - 1][i];
    for (int i = 1; i <= n; i++) {
      int dad = anc[j - 1][i];
      if (dad > 0) rmq[j][dad] = min(rmq[j][dad], rmq[j - 1][i]);
    }
  }
}
struct SimpleTree {
  static constexpr int ID = INF;
  static int compress(const int& lc, const int& rc) { return min(lc, rc); }
  int n;
  vector<int> tree;
  void build(const int& j, const vector<int>& t) {
    n = t.size();
    tree.resize(n + n);
    for (int i = n - 1; i >= 0; i--) {
      int v = rev[t[i]];
      tree[i + n] = rmq[j][v];
    }
    for (int i = n - 1; i > 0; i--)
      tree[i] = compress(tree[i + i], tree[i + i + 1]);
  }
  void modify(int i, const int& u) {
    i += n;
    tree[i] = u;
    for (int p = i >> 1; i > 1; i >>= 1, p >>= 1)
      tree[p] = compress(tree[i], tree[i ^ 1]);
  }
  int query(int l, int r) {
    int lx = ID, rx = ID;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) lx = compress(lx, tree[l++]);
      if (r & 1) rx = compress(tree[--r], rx);
    }
    return compress(lx, rx);
  }
};
SimpleTree T[L][N];
int query(int v, int k) {
  int answer = a[v];
  int depth = dpt[v];
  for (int j = L - 1, b = 1 << j; j >= 0; j--, b >>= 1)
    if (k & b) {
      if (depth > n or layer[depth].empty()) break;
      int lx, rx;
      int lo = 0, hi = layer[depth].size() - 1;
      while (lo < hi) {
        int mid = (lo + hi) / 2;
        if (layer[depth][mid] >= st[v])
          hi = mid;
        else
          lo = mid + 1;
      }
      lx = lo;
      lo = 0, hi = layer[depth].size() - 1;
      while (lo < hi) {
        int mid = (lo + hi) / 2;
        if (layer[depth][mid] > en[v])
          hi = mid;
        else
          lo = mid + 1;
      }
      rx = lo;
      int q = T[j][depth].query(lx, rx);
      answer = min(answer, q);
      depth += b;
    }
  return answer;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int r;
  cin >> n >> r;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int u, v, i = 1; i < n; i++) {
    cin >> u >> v;
    tree[u].emplace_back(v);
    tree[v].emplace_back(u);
  }
  timer = 0;
  df0(r);
  dpt[0] = 0, st[0] = 0, en[0] = timer;
  init_dp();
  for (int depth = 1; depth <= n; depth++)
    if (not layer[depth].empty()) layer[depth].emplace_back(n + 1);
  for (int j = 0; j < L; j++)
    for (int depth = 1; depth <= n; depth++) {
      if (not layer[depth].empty()) {
        T[j][depth].build(j, layer[depth]);
      }
    }
  int m, answer = 0;
  cin >> m;
  while (m--) {
    int p, q;
    cin >> p >> q;
    int v = 1 + (p + answer) % n, k = (q + answer) % n;
    answer = query(v, k);
    cout << answer << '\n';
  }
  return 0;
}
