#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int l[N], d[N], sz[N], a[N];
vector<int> adj[N], st[2][4 * N];
int v1[N], v2[N];
int n, r, q;
int T = 0;
int dfs(int x, int p, int h) {
  l[x] = T++;
  d[x] = h;
  sz[x] = 1;
  v1[l[x]] = d[x];
  v2[l[x]] = a[x];
  for (int v : adj[x])
    if (v != p) sz[x] += dfs(v, x, h + 1);
  return sz[x];
}
void build(int nx = 1, int l = 0, int r = n - 1) {
  if (l == r) {
    st[0][nx].push_back(v1[r]);
    st[1][nx].push_back(v2[r]);
    return;
  }
  int mid = (l + r) / 2;
  build(2 * nx, l, mid);
  build(2 * nx + 1, mid + 1, r);
  int ln = st[0][2 * nx].size();
  int rn = st[0][2 * nx + 1].size();
  int i = 0, j = 0;
  int mini = 1e9;
  while (i < ln and j < rn) {
    if (st[0][2 * nx][i] < st[0][2 * nx + 1][j]) {
      mini = min(mini, st[1][2 * nx][i]);
      st[0][nx].push_back(st[0][2 * nx][i]);
      st[1][nx].push_back(mini);
      i += 1;
    } else {
      mini = min(mini, st[1][2 * nx + 1][j]);
      st[0][nx].push_back(st[0][2 * nx + 1][j]);
      st[1][nx].push_back(mini);
      j += 1;
    }
  }
  while (i < ln) {
    mini = min(mini, st[1][2 * nx][i]);
    st[0][nx].push_back(st[0][2 * nx][i]);
    st[1][nx].push_back(mini);
    i += 1;
  }
  while (j < rn) {
    mini = min(mini, st[1][2 * nx + 1][j]);
    st[0][nx].push_back(st[0][2 * nx + 1][j]);
    st[1][nx].push_back(mini);
    j += 1;
  }
}
int query(int d, int a, int b, int nx = 1, int l = 0, int r = n - 1) {
  if (b < l or a > r) return INT_MAX;
  if (a <= l and r <= b) {
    int lo = 0, hi = (int)st[0][nx].size() - 1;
    while (lo < hi) {
      int mid = lo + (hi - lo + 1) / 2;
      if (st[0][nx][mid] <= d)
        lo = mid;
      else
        hi = mid - 1;
    }
    if (st[0][nx][lo] <= d) return st[1][nx][lo];
    return INT_MAX;
  }
  int mid = (l + r) / 2;
  int L = query(d, a, b, 2 * nx, l, mid);
  int R = query(d, a, b, 2 * nx + 1, mid + 1, r);
  return min(L, R);
}
int main() {
  scanf("%d %d", &n, &r);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(r, 0, 0);
  build();
  scanf("%d", &q);
  int last = 0;
  while (q--) {
    int x, y;
    scanf("%d %d", &x, &y);
    x = (x + last) % n + 1;
    y = (y + last) % n;
    printf("%d\n", (last = query(d[x] + y, l[x], l[x] + sz[x] - 1)));
  }
  return 0;
}
