#include <bits/stdc++.h>
using namespace std;
int dep[100005];
int id[100005];
int val[100005];
vector<int> s[100005];
vector<int> level[100005];
vector<int> inid[100005];
vector<int> tree[100005][20];
int dfs_id;
int dp[100005][20];
int bi[20];
int SZ[100005];
int MAX;
int dfs(int u, int fa, int add) {
  int sum = 1;
  id[u] = ++dfs_id;
  dep[u] = add;
  dp[u][0] = val[u];
  level[add].push_back(u);
  inid[add].push_back(dfs_id);
  MAX = max(MAX, add);
  for (auto v : s[u]) {
    if (v == fa) continue;
    sum += dfs(v, u, add + 1);
  }
  return SZ[u] = sum;
}
void build(vector<int>& T, int L, int V, int root, int l, int r) {
  if (l == r) {
    T[root] = dp[level[L][l]][V];
    return;
  }
  int m = (l + r) / 2;
  build(T, L, V, root * 2, l, m);
  build(T, L, V, root * 2 + 1, m + 1, r);
  T[root] = min(T[root * 2], T[root * 2 + 1]);
}
int query(vector<int>& T, int root, int l, int r, int L, int R) {
  if (r < L || l > R) return 2000000000;
  if (L <= l && r <= R) return T[root];
  int m = (l + r) / 2;
  int first = query(T, root * 2, l, m, L, R);
  int second = query(T, root * 2 + 1, m + 1, r, L, R);
  return min(first, second);
}
int main() {
  bi[0] = 1;
  for (int i = 1; i < 20; i++) bi[i] = bi[i - 1] * 2;
  vector<int> arr;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
  }
  for (int i = 1; i < n; i++) {
    int first, second;
    scanf("%d%d", &first, &second);
    s[first].push_back(second);
    s[second].push_back(first);
  }
  dfs(m, 0, 1);
  for (int i = 1; i <= MAX; i++) {
    for (int j = 0; j <= 18; j++) tree[i][j].resize(level[i].size() * 4);
    build(tree[i][0], i, 0, 1, 0, level[i].size() - 1);
  }
  for (int j = 1; j <= 18; j++) {
    for (int i = 1; i <= n; i++) {
      int mi = dp[i][j - 1];
      int nxt = dep[i] + bi[j - 1];
      if (nxt <= MAX) {
        int ID = id[i];
        int lll = lower_bound(inid[nxt].begin(), inid[nxt].end(), ID) -
                  inid[nxt].begin();
        int rrr = lower_bound(inid[nxt].begin(), inid[nxt].end(), ID + SZ[i]) -
                  inid[nxt].begin() - 1;
        if (rrr >= lll) {
          int tmp =
              query(tree[nxt][j - 1], 1, 0, level[nxt].size() - 1, lll, rrr);
          mi = min(mi, tmp);
        }
      }
      dp[i][j] = mi;
    }
    for (int i = 1; i <= MAX; i++)
      build(tree[i][j], i, j, 1, 0, level[i].size() - 1);
  }
  int t;
  scanf("%d", &t);
  int last = 0;
  while (t--) {
    int first, second;
    scanf("%d%d", &first, &second);
    int X = (first + last) % n + 1;
    int Y = (second + last) % n + 1;
    int ID = id[X];
    int nxt = dep[X];
    int ans = 2000000000;
    for (int d = 0; d <= 18; d++) {
      if (nxt > MAX) break;
      if ((1 << d) & Y) {
        int lll = lower_bound(inid[nxt].begin(), inid[nxt].end(), ID) -
                  inid[nxt].begin();
        int rrr = lower_bound(inid[nxt].begin(), inid[nxt].end(), ID + SZ[X]) -
                  inid[nxt].begin() - 1;
        if (rrr >= lll) {
          int tmp = query(tree[nxt][d], 1, 0, level[nxt].size() - 1, lll, rrr);
          ans = min(ans, tmp);
        }
        nxt += bi[d];
      }
    }
    printf("%d\n", ans);
    last = ans;
  }
}
