#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long md = 1e9 + 7;
void assertion(bool ok) {
  if (!ok) {
    exit(!(cout << -1 << "\n"));
  }
}
vector<vector<vector<vector<int>>>> table;
vector<int> posons[(int)(2e5 + 10)];
int tin[(int)(2e5 + 10)];
int tout[(int)(2e5 + 10)];
int timer;
int a[(int)(2e5 + 10)];
int max_deep;
vector<int> reb[(int)(2e5 + 10)];
int lg[(int)(2e5 + 10)];
int deep_global[(int)(2e5 + 10)];
void dfs(int now, int pred, int deep) {
  deep_global[now] = deep;
  max_deep = max(max_deep, deep);
  tin[now] = ++timer;
  posons[deep].push_back(now);
  for (auto wh : reb[now]) {
    if (wh != pred) {
      dfs(wh, now, deep + 1);
    }
  }
  tout[now] = timer;
}
int get_lol(int deep, int poson, int deep_want_to_know) {
  if (deep > max_deep) {
    return 2e9;
  }
  if (tin[posons[deep].front()] > tout[poson]) {
    return 2e9;
  }
  if (tout[posons[deep].back()] < tin[poson]) {
    return 2e9;
  }
  int l, r;
  l = 0;
  r = (int)(posons[deep].size()) - 1;
  while (r - l > 0) {
    int m = (l + r) / 2;
    if (tout[posons[deep][m]] < tin[poson]) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  int res1 = l;
  l = 0;
  r = (int)(posons[deep].size()) - 1;
  while (r - l > 0) {
    int m = (l + r + 1) / 2;
    if (tin[posons[deep][m]] > tout[poson]) {
      r = m - 1;
    } else {
      l = m;
    }
  }
  int res2 = l;
  if (res1 > res2) {
    return 2e9;
  }
  int log2_ = lg[res2 - res1 + 1];
  return min(table[deep][deep_want_to_know][res1][log2_],
             table[deep][deep_want_to_know][res2 - (1ll << log2_) + 1][log2_]);
}
void build() {
  table.resize(max_deep + 1);
  for (int i = 0; i < (int)(table.size()); i++) {
    table[i].resize(18);
    for (int j = 0; j < (int)(table[i].size()); j++) {
      table[i][j].resize((int)(posons[i].size()));
      for (int k = 0; k < (int)(table[i][j].size()); k++) {
        table[i][j][k].push_back(0);
        while (k + (1ll << ((int)(table[i][j][k].size()) - 1)) - 1 <
               (int)(table[i][j].size()) - 1) {
          table[i][j][k].push_back(0);
        }
      }
    }
  }
  for (int i = max_deep; i >= 0; i--) {
    for (int k = 0; k < (int)(table[i][0].size()); k++) {
      table[i][0][k][0] = a[posons[i][k]];
    }
    for (int j = 1; j < 18; j++) {
      for (int k = 0; k < (int)(table[i][j].size()); k++) {
        table[i][j][k][0] =
            min(table[i][j - 1][k][0],
                get_lol(i + (1ll << (j - 1)), posons[i][k], j - 1));
      }
    }
    for (int j = 0; j < 18; j++) {
      for (int l = 1; 0 + (1ll << l) - 1 < (int)(table[i][j].size()); l++) {
        for (int k = 0; k + (1ll << l) - 1 < (int)(table[i][j].size()); k++) {
          table[i][j][k][l] = min(table[i][j][k][l - 1],
                                  table[i][j][k + (1ll << (l - 1))][l - 1]);
        }
      }
    }
  }
}
int get_lalka(int deep, int poson, int k) {
  if (k <= 0) {
    return 2e9;
  }
  if (deep > max_deep) {
    return 2e9;
  }
  if (tin[posons[deep].front()] > tout[poson]) {
    return 2e9;
  }
  if (tout[posons[deep].back()] < tin[poson]) {
    return 2e9;
  }
  int l, r;
  l = 0;
  r = (int)(posons[deep].size()) - 1;
  while (r - l > 0) {
    int m = (l + r) / 2;
    if (tout[posons[deep][m]] < tin[poson]) {
      l = m + 1;
    } else {
      r = m;
    }
  }
  int res1 = l;
  l = 0;
  r = (int)(posons[deep].size()) - 1;
  while (r - l > 0) {
    int m = (l + r + 1) / 2;
    if (tin[posons[deep][m]] > tout[poson]) {
      r = m - 1;
    } else {
      l = m;
    }
  }
  int res2 = l;
  if (res1 > res2) {
    return 2e9;
  }
  int loog2_ = lg[k];
  int log2_ = lg[res2 - res1 + 1];
  return min({table[deep][loog2_][res1][log2_],
              table[deep][loog2_][res2 - (1ll << log2_) + 1][log2_],
              get_lalka(deep + (1ll << loog2_), poson, k - (1ll << loog2_))});
}
int get(int x, int k) {
  k++;
  return get_lalka(deep_global[x], x, k);
}
int main() {
  for (int i = 2; i < (int)(2e5 + 10); i++) {
    lg[i] = lg[i / 2] + 1;
  }
  int n, r;
  scanf("%d%d", &n, &r);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    reb[u].push_back(v);
    reb[v].push_back(u);
  }
  dfs(r, -1, 0);
  build();
  int m;
  scanf("%d", &m);
  int last = 0;
  int number_of_request = 0;
  while (m--) {
    number_of_request++;
    int p, q;
    scanf("%d%d", &p, &q);
    int x = (p + last) % n + 1;
    int k = (q + last) % n;
    cout << (last = get(x, k)) << "\n";
  }
}
