#include <bits/stdc++.h>
using namespace std;
long long po(long long a, long long b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2) {
      x = x * y;
      x %= 1000000007;
    }
    y = y * y;
    y %= 1000000007;
    b /= 2;
  }
  return x;
}
static int a[200005];
static int st[200005], en[200005];
vector<pair<int, int> > order;
vector<int> adj[200005];
static int mohib[200005];
void dfs0(int cur, int pr, int lvl) {
  mohib[cur] = lvl;
  order.push_back(make_pair(lvl, a[cur]));
  st[cur] = order.size() - 1;
  for (int i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] == pr) {
      continue;
    }
    dfs0(adj[cur][i], cur, lvl + 1);
  }
  en[cur] = order.size() - 1;
}
vector<pair<int, int> > seg[400005];
void build(int s, int e, int ind) {
  if (s == e) {
    seg[ind].push_back(order[s]);
    return;
  }
  int mi = (s + e) >> 1;
  build(s, mi, 2 * ind + 1);
  build(mi + 1, e, 2 * ind + 2);
  for (int i = s; i <= e; i++) {
    seg[ind].push_back(order[i]);
  }
  sort(seg[ind].begin(), seg[ind].end());
  for (int i = 1; i < seg[ind].size(); i++) {
    seg[ind][i].second = min(seg[ind][i].second, seg[ind][i - 1].second);
  }
  return;
}
int query(int s, int e, int ind, int qs, int qe, int val) {
  if (s > qe || e < qs) {
    return INT_MAX;
  }
  if (qs <= s && e <= qe) {
    int now = 1e9 + 2;
    int lo = 0, high = seg[ind].size() - 1;
    while (lo <= high) {
      int mi = (lo + high) >> 1;
      if (seg[ind][mi].first <= val) {
        now = seg[ind][mi].second;
        lo = mi + 1;
      } else {
        high = mi - 1;
      }
    }
    return now;
  }
  int mi = (s + e) >> 1;
  return min(query(s, mi, 2 * ind + 1, qs, qe, val),
             query(mi + 1, e, 2 * ind + 2, qs, qe, val));
}
int main() {
  if (0) {
    freopen("C:/Users/gold/Desktop/sublime IO/input.txt", "r", stdin);
    freopen("C:/Users/gold/Desktop/sublime IO/output.txt", "w", stdout);
  }
  int T = 1;
  while (T--) {
    int n, r;
    scanf("%d %d", &n, &r);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs0(r, -1, 0);
    build(0, n - 1, 0);
    int last = 0;
    int m;
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      int p, q;
      scanf("%d %d", &p, &q);
      p = (last + p) % n + 1;
      q = (last + q) % n;
      printf("%d\n", last = query(0, n - 1, 0, st[p], en[p], mohib[p] + q));
    }
  }
  return 0;
}
