#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1 &a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1 &a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <int MOD>
struct ModInt {
  unsigned x;
  ModInt() : x(0) {}
  ModInt(signed sig) : x(sig) {}
  ModInt(signed long long sig) : x(sig % MOD) {}
  int get() const { return (int)x; }
  ModInt pow(long long p) {
    ModInt res = 1, a = *this;
    while (p) {
      if (p & 1) res *= a;
      a *= a;
      p >>= 1;
    }
    return res;
  }
  ModInt &operator+=(ModInt that) {
    if ((x += that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator-=(ModInt that) {
    if ((x += MOD - that.x) >= MOD) x -= MOD;
    return *this;
  }
  ModInt &operator*=(ModInt that) {
    x = (unsigned long long)x * that.x % MOD;
    return *this;
  }
  ModInt &operator/=(ModInt that) { return (*this) *= that.pow(MOD - 2); }
  ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
  ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
  ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
  ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
  bool operator<(ModInt that) const { return x < that.x; }
  friend ostream &operator<<(ostream &os, ModInt a) {
    os << a.x;
    return os;
  }
};
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
struct node {
  vector<pair<int, int> > a;
  vector<int> st;
};
const int N = 100001, inf = 1e9;
int a[N];
int dep[N], ndep;
node st[N * 2];
vector<int> g[N];
int in[N], out[N], ct;
void dfs(int i, int p) {
  dep[i] = dep[p] + 1;
  Max(ndep, dep[i]);
  in[i] = ++ct;
  for (auto &e : g[i])
    if (e != p) {
      dfs(e, i);
    }
  out[i] = ct;
}
int que(int i, int l, int r) {
  l = lower_bound(st[i].a.begin(), st[i].a.end(), pair<int, int>{l, 0}) -
      st[i].a.begin();
  r = upper_bound(st[i].a.begin(), st[i].a.end(), pair<int, int>{r, inf}) -
      st[i].a.begin();
  int ans = inf;
  for (l += st[i].a.size(), r += st[i].a.size(); l < r; l >>= 1, r >>= 1) {
    if (l & 1) Min(ans, st[i].st[l++]);
    if (r & 1) Min(ans, st[i].st[--r]);
  }
  return ans;
}
void solve() {
  int n, r, x, y, m;
  cin >> n >> r;
  for (int i = 1; i <= (n); ++i) cin >> a[i];
  for (int it = 0; it < (n - 1); ++it) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(r, 0);
  ndep++;
  for (int i = 1; i <= (n); ++i) {
    int d = dep[i];
    pair<int, int> v = {in[i], a[i]};
    for (d += ndep; d; d >>= 1) {
      st[d].a.push_back(v);
    }
  }
  for (int d = 1; d <= (ndep * 2 - 1); ++d) {
    sort(st[d].a.begin(), st[d].a.end());
    int n = st[d].a.size();
    st[d].st.assign(n * 2, inf);
    for (int i = 0; i < (n); ++i) st[d].st[i + n] = st[d].a[i].second;
    for (int i = n - 1; i >= (1); --i)
      st[d].st[i] = min(st[d].st[i << 1], st[d].st[i << 1 | 1]);
  }
  cin >> m;
  int ans = 0;
  while (m--) {
    cin >> x >> y;
    x = (x + ans) % n + 1;
    y = (y + ans) % n;
    int l = dep[x], r = l + y;
    Min(r, ndep - 1);
    int tl = in[x], tr = out[x];
    ans = inf;
    for (l += ndep, r += ndep + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) Min(ans, que(l++, tl, tr));
      if (r & 1) Min(ans, que(--r, tl, tr));
    }
    cout << ans << '\n';
  }
}
void init() {}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  init();
  int TC = 1;
  for (int TI = 1; TI <= (TC); ++TI) {
    solve();
  }
  return 0;
}
