#include <bits/stdc++.h>
using namespace std;
template <class Val, class Cmp>
class DynamicRMQ {
  int n;
  Val init;
  vector<Val> dat;
  Cmp cmp;
  inline Val query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return init;
    if (a <= l && r <= b)
      return dat[k];
    else {
      Val vl, vr;
      vl = query(a, b, k << 1, l, (l + r) >> 1);
      vr = query(a, b, (k << 1) | 1, (l + r) >> 1, r);
      return cmp(vl, vr) ? vl : vr;
    }
  }

 public:
  DynamicRMQ() {}
  DynamicRMQ(int n_, Val init_) : n(1), init(init_) {
    for (; n < n_; n <<= 1)
      ;
    dat = vector<Val>(n << 1, init);
  }
  void update(int k, Val a) {
    k += n;
    dat[k] = a;
    while (k > 1) {
      k >>= 1;
      dat[k] =
          cmp(dat[k << 1], dat[(k << 1) | 1]) ? dat[k << 1] : dat[(k << 1) | 1];
    }
  }
  Val query(int a, int b) { return query(a, b, 1, 0, n); }
};
const int N_MAX = 100005, LOG = 18;
int N, R, A[N_MAX];
int e2v[N_MAX], v2e[N_MAX];
int euler_l[N_MAX], euler_r[N_MAX];
int id, depth[N_MAX], ancestor[LOG][N_MAX], min_a[LOG][N_MAX], bfs_id[N_MAX];
vector<int> G[N_MAX];
vector<pair<int, int> > ordered[N_MAX + N_MAX];
DynamicRMQ<int, less<int> > rmq[LOG];
void f(int u, int p, int d) {
  e2v[id] = u;
  euler_l[u] = v2e[u] = id;
  ordered[d].emplace_back(id++, 0);
  depth[u] = d;
  ancestor[0][u] = p != -1 ? p : u;
  for (int(j) = (0); (j) < (int)(LOG); ++(j))
    (min_a[j][u]) = min((min_a[j][u]), (A[u]));
  (min_a[0][ancestor[0][u]]) = min((min_a[0][ancestor[0][u]]), (A[u]));
  for (auto &(v) : (G[u]))
    if (p != v) {
      f(v, u, d + 1);
    }
  euler_r[u] = id;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> R;
  --R;
  for (int(i) = (0); (i) < (int)(N); ++(i)) cin >> A[i];
  for (int(i) = (0); (i) < (int)(N - 1); ++(i)) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int(i) = (0); (i) < (int)(LOG); ++(i)) {
    rmq[i] = DynamicRMQ<int, less<int> >(N, 1 << 30);
    for (int(j) = (0); (j) < (int)(N); ++(j)) min_a[i][j] = 1 << 30;
  }
  f(R, -1, 0);
  id = 0;
  for (int(i) = (0); (i) < (int)(N); ++(i))
    for (auto &(p) : (ordered[i])) {
      bfs_id[e2v[p.first]] = p.second = id++;
    }
  for (int(i) = (0); (i) < (int)(LOG - 1); ++(i)) {
    for (int(j) = (0); (j) < (int)(N); ++(j)) {
      ancestor[i + 1][j] = ancestor[i][ancestor[i][j]];
      (min_a[i + 1][j]) = min((min_a[i + 1][j]), (min_a[i][j]));
      (min_a[i + 1][ancestor[i][j]]) =
          min((min_a[i + 1][ancestor[i][j]]), (min_a[i][j]));
    }
    for (int(j) = (0); (j) < (int)(N); ++(j))
      rmq[i].update(bfs_id[j], min_a[i][j]);
  }
  int M, ans = 0;
  cin >> M;
  while (M--) {
    int p, q, X, K;
    cin >> p >> q;
    X = (p + ans) % N;
    K = (q + ans) % N;
    ans = A[X];
    int dep = depth[X];
    for (int(i) = (0); (i) < (int)(LOG - 1); ++(i))
      if (K >> i & 1) {
        auto l = lower_bound((ordered[dep]).begin(), (ordered[dep]).end(),
                             make_pair(euler_l[X], 0));
        auto r = lower_bound((ordered[dep]).begin(), (ordered[dep]).end(),
                             make_pair(euler_r[X], 0));
        while (l != r) {
          --r;
          (ans) = min((ans), (rmq[i].query(l->second, r->second + 1)));
        }
        dep += 1 << i;
      }
    cout << ans << endl;
  }
}
