#include <bits/stdc++.h>
using namespace std;
struct dor {
  vector<pair<int, int> > v;
  vector<int> ve;
  dor *l, *r;
  dor() {
    l = r = NULL;
    v.clear();
    ve.clear();
  }
  void pump() {
    v.clear();
    ve.clear();
    int dl = 0, dr = 0, n = (int)((l->v).size()), m = (int)((r->v).size());
    while (dl < n || dr < m) {
      if (dl == n) {
        v.push_back((r->v)[dr++]);
      } else if (dr == m) {
        v.push_back((l->v)[dl++]);
      } else {
        if ((l->v)[dl].first == (r->v)[dr].first) {
          if ((l->v)[dl].second < (r->v)[dr].second) {
            v.push_back((l->v)[dl++]);
          } else {
            v.push_back((r->v)[dr++]);
          }
        } else if ((l->v)[dl].first < (r->v)[dr].first) {
          v.push_back((l->v)[dl++]);
        } else {
          v.push_back((r->v)[dr++]);
        }
      }
    }
    dl = 1e9;
    for (int i = 0; i < v.size(); ++i) {
      if (i) dl = ve[i - 1];
      ve.push_back(min(dl, v[i].second));
    }
  }
  int tsh(int k) {
    int bl = 0, br = (int)(v.size()), bm = 0, bp = -1;
    --br;
    while (bl <= br) {
      bm = (bl + br) / 2;
      if (v[bm].first <= k) {
        bp = bm;
        bl = bm + 1;
      } else {
        br = bm - 1;
      }
    }
    if (bp != -1) return ve[bp];
    return 1e9;
  }
};
int n, rt, m, a[100005], x, y, p, q, tp, k, io[100005][2], rg, ddt[100005];
pair<int, int> b[100005];
vector<int> v[100005];
dor *rtt;
void dfs(int dg, int dt, int up) {
  ddt[dg] = dt;
  io[dg][0] = ++rg;
  b[rg] = {dt, a[dg]};
  for (int i = 0; i < v[dg].size(); ++i) {
    if (v[dg][i] != up) {
      dfs(v[dg][i], dt + 1, dg);
    }
  }
  io[dg][1] = rg;
}
void bgbn(int l, int r, dor *&t) {
  if (t == NULL) t = new dor();
  if (l == r) {
    (t->v).push_back(b[l]);
    (t->ve).push_back(b[l].second);
    return;
  }
  bgbn(l, (l + r) / 2, t->l);
  bgbn((l + r) / 2 + 1, r, t->r);
  t->pump();
}
int poi(int l, int r, int sl, int sr, dor *&t) {
  if (l > sr || r < sl) {
    return 1e9;
  }
  if (l >= sl && r <= sr) {
    return t->tsh(k);
  }
  return min(poi(l, (l + r) / 2, sl, sr, t->l),
             poi((l + r) / 2 + 1, r, sl, sr, t->r));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> rt;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i < n; ++i) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(rt, 0, 0);
  bgbn(1, n, rtt);
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> p >> q;
    x = (p + tp) % n + 1;
    k = (q + tp) % n + ddt[x];
    tp = poi(1, n, io[x][0], io[x][1], rtt);
    cout << tp << endl;
  }
}
