#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 100000 + 5;
const int inf = numeric_limits<int>::max();
struct input {
  input() : visited(false) {}
  int key;
  bool visited;
};
input vertices[MAX_SIZE];
vector<vector<pair<int, int> > > values(4 * MAX_SIZE);
vector<vector<int> > mins(4 * MAX_SIZE);
int level[MAX_SIZE], tree[MAX_SIZE], in[MAX_SIZE], out[MAX_SIZE];
int timer;
vector<vector<int> > edges(MAX_SIZE);
void dfs(int node, int parent, int root_dist) {
  if (vertices[node].visited) return;
  vertices[node].visited = true;
  timer++;
  in[node] = timer;
  level[timer] = root_dist;
  tree[timer] = vertices[node].key;
  for (int i = 0; i < edges[node].size(); i++)
    if (edges[node][i] != parent) dfs(edges[node].at(i), node, root_dist + 1);
  out[node] = timer;
}
void buildTree(int node, int left, int right) {
  if (left == right) {
    values[node].emplace_back(level[left], tree[left]);
    mins[node].push_back(tree[left]);
    return;
  }
  int mid = (left + right) / 2;
  buildTree(node * 2, left, mid);
  buildTree(node * 2 + 1, mid + 1, right);
  values[node].resize(values[node * 2].size() + values[node * 2 + 1].size());
  merge(values[node * 2].begin(), values[node * 2].end(),
        values[node * 2 + 1].begin(), values[node * 2 + 1].end(),
        values[node].begin());
  int min = values[node].front().second;
  for (auto i : values[node]) {
    min = i.second < min ? i.second : min;
    mins[node].push_back(min);
  }
}
int query(int node, int left, int right, int i, int j, int x) {
  if (i > right || j < left) return inf;
  if (i <= left && j >= right) {
    int idx = upper_bound(values[node].begin(), values[node].end(),
                          pair<int, int>(x, inf)) -
              values[node].begin();
    if (!idx) return inf;
    idx--;
    return mins[node][idx];
  }
  int mid = (left + right) / 2;
  return min(query(node * 2, left, mid, i, j, x),
             query(node * 2 + 1, mid + 1, right, i, j, x));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int vertex_count, root_index;
  cin >> vertex_count >> root_index;
  for (int i = 1; i <= vertex_count; i++) cin >> vertices[i].key;
  for (int i = 1; i < vertex_count; i++) {
    int from, to;
    cin >> from >> to;
    edges[to].push_back(from);
    edges[from].push_back(to);
  }
  dfs(root_index, 0, 0);
  buildTree(1, 1, vertex_count);
  int query_count, last = 0;
  cin >> query_count;
  for (int i = 0; i < query_count; i++) {
    int p, q;
    cin >> p >> q;
    int x = ((p + last) % vertex_count) + 1;
    int k = (q + last) % vertex_count;
    last = query(1, 1, vertex_count, in[x], out[x], level[in[x]] + k);
    cout << last << endl;
  }
  return 0;
}
