#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int pr[MAX];
int ht[MAX];
int tin[MAX];
int tout[MAX];
int rev[MAX];
vector<int> adj[MAX];
vector<int> val[MAX * 4];
vector<int> vech[MAX * 4];
int tim;
void dfs(int s, int p) {
  tin[s] = (++tim);
  rev[tim] = s;
  for (int i = 0; i < adj[s].size(); i++) {
    int u = adj[s][i];
    if (u != p) {
      ht[u] = ht[s] + 1;
      dfs(u, s);
    }
  }
  tout[s] = tim;
}
void merge(int pos) {
  int ptr1 = 0;
  int ptr2 = 0;
  int lft = 2 * pos;
  int rgt = pos + pos + 1;
  while (ptr1 < val[lft].size() && ptr2 < val[rgt].size()) {
    if (vech[lft][ptr1] == vech[rgt][ptr2]) {
      vech[pos].push_back(vech[lft][ptr1]);
      val[pos].push_back(min(val[lft][ptr1], val[rgt][ptr2]));
      ptr1++;
      ptr2++;
    } else if (vech[lft][ptr1] < vech[rgt][ptr2]) {
      vech[pos].push_back(vech[lft][ptr1]);
      val[pos].push_back(val[lft][ptr1]);
      ptr1++;
    } else {
      vech[pos].push_back(vech[rgt][ptr2]);
      val[pos].push_back(val[rgt][ptr2]);
      ptr2++;
    }
  }
  for (int i = ptr1; i < val[lft].size(); i++) {
    vech[pos].push_back(vech[lft][i]);
    val[pos].push_back(val[lft][i]);
  }
  for (int i = ptr2; i < val[rgt].size(); i++) {
    vech[pos].push_back(vech[rgt][i]);
    val[pos].push_back(val[rgt][i]);
  }
  for (int i = 1; i < val[pos].size(); i++) {
    val[pos][i] = min(val[pos][i - 1], val[pos][i]);
  }
}
void build(int pos, int l, int r) {
  if (l == r) {
    int s = rev[l];
    vech[pos].push_back(ht[s]);
    val[pos].push_back(pr[s]);
    return;
  }
  int mid = (l + r) / 2;
  build(pos + pos, l, mid);
  build(pos + pos + 1, mid + 1, r);
  merge(pos);
}
int query(int pos, int l, int r, int ql, int qr, int y) {
  if (ql > r || qr < l) {
    return 1e9 + 5;
  }
  if (l >= ql && r <= qr) {
    int x = upper_bound(vech[pos].begin(), vech[pos].end(), y) -
            vech[pos].begin() - 1;
    if (x < 0) {
      return 1e9 + 5;
    } else {
      return val[pos][x];
    }
  }
  int mid = (l + r) / 2;
  int a = query(pos + pos, l, mid, ql, qr, y);
  int b = query(pos + pos + 1, mid + 1, r, ql, qr, y);
  return min(a, b);
}
int main() {
  int n, r;
  scanf("%d %d", &n, &r);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &pr[i]);
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(r, 0);
  build(1, 1, n);
  int q;
  scanf("%d", &q);
  int last = 0;
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x = ((x + last) % n) + 1;
    y = ((y + last) % n);
    last = query(1, 1, n, tin[x], tout[x], min(ht[x] + y, n));
    printf("%d\n", last);
  }
  return 0;
}
