#include <bits/stdc++.h>
using namespace std;
struct nodo {
  long long v;
  int izq;
  int der;
};
struct pst {
  vector<int> roots;
  vector<nodo> nodos;
  int n;
};
pst init(int n) {
  pst tree;
  long long k = 1;
  while (k < n) k *= 2;
  tree.nodos.resize(2 * k);
  tree.roots.push_back(1);
  tree.n = k;
  for (int i = 0; i < (int)(2 * k); ++i) {
    tree.nodos[i].v = 1000000000;
    if (i <= k) {
      tree.nodos[i].izq = 2 * i;
      tree.nodos[i].der = 2 * i + 1;
    } else {
      tree.nodos[i].izq = -1;
      tree.nodos[i].der = -1;
    }
  }
  return tree;
}
void update(pst& tree, long long p, long long v) {
  vector<int> camino;
  int act = tree.roots[tree.roots.size() - 1];
  int l = 0, r = tree.n;
  while (r - l > 1) {
    camino.push_back(act);
    if (p < (r + l) / 2) {
      act = tree.nodos[act].izq;
      r = (r + l) / 2;
    } else {
      act = tree.nodos[act].der;
      l = (r + l) / 2;
    }
  }
  nodo nnodo;
  nnodo.v = v;
  nnodo.izq = -1;
  nnodo.der = -1;
  tree.nodos.push_back(nnodo);
  for (int i = (camino.size()) - 1; i >= 0; --i) {
    nnodo = tree.nodos[camino[i]];
    nnodo.v = min(nnodo.v, v);
    if (p % 2) {
      nnodo.der = tree.nodos.size() - 1;
    } else {
      nnodo.izq = tree.nodos.size() - 1;
    }
    tree.nodos.push_back(nnodo);
    p /= 2;
  }
  tree.roots.push_back(tree.nodos.size() - 1);
}
long long get(pst& tree, int act, int l, int r, int a, int b) {
  if (a >= l && b <= r) return tree.nodos[act].v;
  if (b <= l || a >= r) return 1000000000;
  int c = (a + b) / 2;
  return min(get(tree, tree.nodos[act].izq, l, r, a, c),
             get(tree, tree.nodos[act].der, l, r, c, b));
}
long long get(pst& tree, int l, int r, int t) {
  return get(tree, tree.roots[t], l, r, 0, tree.n);
}
void dfs(int act, int p, vector<int>& rec, vector<vector<int>>& grafo) {
  rec.push_back(act);
  for (int i = 0; i < (int)(grafo[act].size()); ++i) {
    if (grafo[act][i] != p) {
      dfs(grafo[act][i], act, rec, grafo);
    }
  }
  rec.push_back(act);
}
int main() {
  int n, r;
  scanf("%d %d", &n, &r);
  vector<vector<int>> grafo(n);
  vector<int> pesos(n);
  for (int i = 0; i < (int)(n); ++i) {
    scanf("%d", &(pesos[i]));
  }
  for (int i = 0; i < (int)(n - 1); ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    grafo[a].push_back(b);
    grafo[b].push_back(a);
  }
  vector<int> nodos;
  dfs(r - 1, -1, nodos, grafo);
  vector<vector<int>> pos(n);
  for (int i = 0; i < (int)(nodos.size()); ++i) {
    pos[nodos[i]].push_back(i);
  }
  pst tree = init(nodos.size());
  vector<int> dist(n, -1);
  vector<int> ts;
  dist[r - 1] = 0;
  queue<int> bfs;
  bfs.push(r - 1);
  int actd = 0;
  while (!bfs.empty()) {
    int act = bfs.front();
    if (dist[act] > actd) {
      ts.push_back(tree.roots.size() - 1);
    }
    actd = dist[act];
    for (int i = 0; i < (int)(pos[act].size()); ++i) {
      update(tree, pos[act][i], pesos[act]);
    }
    for (int i = 0; i < (int)(grafo[act].size()); ++i) {
      int next = grafo[act][i];
      if (dist[next] == -1) {
        bfs.push(next);
        dist[next] = dist[act] + 1;
      }
    }
    bfs.pop();
  }
  ts.push_back(tree.roots.size() - 1);
  int m;
  scanf("%d", &m);
  long long last = 0;
  for (int i = 0; i < (int)(m); ++i) {
    long long p, q;
    scanf("%I64d %I64d", &p, &q);
    long long x = (p + last) % n, k = (q + last) % n;
    k += dist[x];
    k = min(k, (long long)ts.size() - 1);
    last = get(tree, pos[x][0], pos[x][1], ts[k]);
    printf("%I64d\n", last);
  }
  return 0;
}
