#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5;
const int LOG = 16;
struct trie {
  int go[N][2], NFI = 1;
  trie() { memset(go, -1, sizeof(go)); }
  void reset() {
    for (int i = 0; i <= NFI; i++) go[i][0] = go[i][1] = -1;
    NFI = 1;
  }
  void add(int x) {
    for (int at = 1, bit = LOG - 1; bit >= 0; bit--) {
      int t = x >> bit & 1;
      if (go[at][t] == -1) go[at][t] = ++NFI;
      at = go[at][t];
    }
  }
  int ask(int x) {
    int res = 0;
    for (int at = 1, bit = LOG - 1; bit >= 0; bit--) {
      int t = x >> bit & 1;
      if (go[at][!t] != -1) {
        res |= (1 << bit);
        at = go[at][!t];
      } else
        at = go[at][t];
    }
    return res;
  }
} t;
int n, q, a[N];
vector<int> nb[N];
int par[N], dep[N], jump_256[N];
void DFS_prep(int v) {
  for (int u : nb[v]) {
    if (u != par[v]) {
      par[u] = v;
      dep[u] = dep[v] + 1;
      DFS_prep(u);
    }
  }
}
int res[N][256];
void precalc(int v) {
  t.reset();
  int temp = v;
  for (int i = 0; i <= 255; i++) {
    t.add(a[temp] ^ i);
    temp = par[temp];
  }
  jump_256[v] = temp;
  for (int i = 0; i < 256; i++) res[v][i] = t.ask(i * 256);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    nb[u].push_back(v);
    nb[v].push_back(u);
  }
  DFS_prep(1);
  for (int i = 1; i <= n; i++)
    if (dep[i] >= 255) precalc(i);
  while (q--) {
    int u, v;
    cin >> u >> v;
    int ans = 0;
    int jumps = 0;
    while (v && dep[v] - dep[u] >= 255) {
      ans = max(ans, res[v][jumps]);
      jumps++;
      v = jump_256[v];
    }
    jumps *= 256;
    while (v && dep[v] >= dep[u]) {
      ans = max(ans, a[v] ^ jumps);
      v = par[v];
      jumps++;
    }
    cout << ans << '\n';
  }
  return 0;
}
