#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50505, B = 256, LG = 8, FULL = 255;
int n, q, a[MAXN], trie[MAXN][B], fath[MAXN], depth[MAXN], anc256[MAXN];
vector<int> G[MAXN];
void upd(int &x, int y) {
  if (x < y) x = y;
}
void dfs(int v, int fa, int dep) {
  fath[v] = fa, depth[v] = dep;
  int p = v;
  for (int i = 0; i < B; ++i) {
    int x = (a[p] & FULL) ^ i;
    upd(trie[v][FULL ^ (a[p] >> LG)], x | (FULL << LG));
    if (p == 1) break;
    p = fath[p];
  }
  anc256[v] = p;
  for (int j = 0; j < LG; ++j)
    for (int S = 0; S < B; ++S)
      if (trie[v][S ^ (1 << j)])
        upd(trie[v][S], trie[v][S ^ (1 << j)] ^ (1 << (j + LG)));
  for (auto u : G[v])
    if (u != fa) {
      dfs(u, v, dep + 1);
    }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i < n; ++i) {
    static int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 1, 1);
  while (q--) {
    static int u, v, v0;
    scanf("%d%d", &u, &v), v0 = v;
    int ans = a[u] ^ (depth[v] - depth[u]);
    for (int fr = 0; depth[v] - depth[u] >= B; ++fr) {
      upd(ans, trie[v][fr]);
      v = anc256[v];
    }
    while (v != u) {
      upd(ans, a[v] ^ (depth[v0] - depth[v]));
      v = fath[v];
    }
    printf("%d\n", ans);
  }
  return 0;
}
