#include <bits/stdc++.h>
using namespace std;
vector<int> v[150005], w[150005];
vector<int>::iterator it;
void chkmin(int &a, int b) {
  if (a > b) a = b;
}
int n, rt, a[150005], st[150005], fs[150005], G, dp[150005];
int rg[150005][18], lg[150005][18], b[150005];
int mn[150005][18][18];
const int inf = 0x3f3f3f3f;
void dfs(int k, int pa = 0) {
  dp[k] = dp[pa] + 1;
  st[k] = ++G;
  w[dp[k]].push_back(k);
  for (auto x : v[k]) {
    if (x == pa) continue;
    dfs(x, k);
  }
  fs[k] = ++G;
  return;
}
bool cmp1(int x, int y) { return st[x] < st[y]; }
bool cmp2(int x, int y) { return fs[x] < fs[y]; }
int find_min(int l, int r, int k) {
  if (!l || !r) return inf;
  int ll = b[l], rr = b[r];
  if (ll > rr) return inf;
  int m = 31 - __builtin_clz(rr - ll + 1);
  r = w[dp[l]][rr - (1 << m) + 1];
  return min(mn[l][k][m], mn[r][k][m]);
}
void build() {
  for (int i = n; i; i--) {
    if (w[i].empty()) continue;
    int sz = w[i].size();
    for (auto x : w[i]) mn[x][0][0] = a[x];
    for (int j = 1; j < 18; j++) {
      if (sz < (1 << j)) break;
      for (auto x : w[i]) {
        if (b[x] + (1 << j) > sz) break;
        mn[x][0][j] =
            min(mn[x][0][j - 1], mn[w[i][b[x] + (1 << j - 1)]][0][j - 1]);
      }
    }
    for (auto x : w[i]) {
      for (int j = 1; j < 18; j++) {
        for (int jj = 0; jj < 18; jj++) {
          if (b[x] + (1 << jj) > sz) break;
          mn[x][j][jj] = mn[x][j - 1][jj];
          chkmin(mn[x][j][jj],
                 find_min(lg[x][j], rg[w[i][b[x] + (1 << jj) - 1]][j], j - 1));
        }
      }
    }
  }
  return;
}
int query(int x, int y) {
  y++;
  int res = inf, l = x, r = x;
  for (int i = 18 - 1; i >= 0; i--) {
    if (y >= (1 << i)) {
      chkmin(res, find_min(l, r, i));
      l = lg[l][i + 1], r = rg[r][i + 1];
      if (!l || !r) return res;
      y -= (1 << i);
    }
  }
  return res;
}
int main() {
  scanf("%d %d", &n, &rt);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int x, y;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  memset(mn, 0x3f, sizeof mn);
  dfs(rt, 0);
  st[0] = n + 1;
  for (int i = 0; i <= n; i++) {
    lg[i][0] = i;
    rg[i][0] = i;
    for (int j = 1; j < 18; j++) {
      x = dp[i] + (1 << j - 1);
      if (w[x].empty()) break;
      it = lower_bound(w[x].begin(), w[x].end(), i, cmp1);
      if (it != w[x].end()) lg[i][j] = *it;
      it = lower_bound(w[x].begin(), w[x].end(), i, cmp2);
      if (it != w[x].begin()) --it, rg[i][j] = *it;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < w[i].size(); j++) {
      b[w[i][j]] = j;
    }
  }
  build();
  int q, lst = 0;
  for (scanf("%d", &q); q--;) {
    scanf("%d %d", &x, &y);
    x = (x + lst) % n + 1;
    y = (y + lst) % n;
    lst = query(x, y);
    printf("%d\n", lst);
  }
  return 0;
}
