#include <bits/stdc++.h>
using namespace std;
int n, m, q, cnt;
int Head[50100], date[100100], Next[100100], tot;
int a[50100], f[50100][300], maxn[50100][300], c[50100][2], fa[50100],
    dep[50100], jump[50100];
int vis[256];
inline int read() {
  int x = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
inline void upmax(int &a, int b) {
  if (b > a) a = b;
}
void add(int f, int w) {
  date[++tot] = w, Next[tot] = Head[f], Head[f] = tot;
  date[++tot] = f, Next[tot] = Head[w], Head[w] = tot;
}
void ins(int x) {
  int now = 0, tmp = 1 << 7;
  for (register int i = 1; i <= 8; i++, tmp >>= 1) {
    int v = (x & tmp) > 0;
    if (!c[now][v]) c[now][v] = ++cnt, c[cnt][0] = c[cnt][1] = 0;
    now = c[now][v];
  }
}
int query(int x, int sta) {
  int now = 0, rnt = 0, v = 0, tmp = 1 << 7;
  for (register int i = 1; i <= 8; i++, tmp >>= 1) {
    int go = !(sta & tmp);
    if (c[now][go])
      rnt |= tmp;
    else
      go ^= 1;
    now = c[now][go];
    if (go) v |= tmp;
  }
  return (rnt << 8) | maxn[x][v];
}
void dfs(int x) {
  if (dep[x] >= 256) {
    cnt = c[0][0] = c[0][1] = 0;
    for (register int i = x; (dep[x] - dep[i]) <= 255; i = fa[i]) {
      int tmp = a[i] >> 8;
      upmax(maxn[x][tmp], (a[i] ^ (dep[x] - dep[i])) & 255);
      if (vis[tmp] != x) ins(tmp), vis[tmp] = x;
      if ((dep[x] - dep[i]) == 255) jump[x] = fa[i];
    }
    for (register int i = 0; i <= 255; i++) f[x][i] = query(x, i);
  }
  for (register int i = Head[x]; i; i = Next[i]) {
    int now = date[i];
    if (now == fa[x]) continue;
    dep[now] = dep[x] + 1, fa[now] = x, dfs(now);
  }
}
void pre() {
  n = read(), q = read(), dep[1] = 1;
  for (register int i = 1; i <= n; i++) a[i] = read();
  for (register int i = 1; i < n; i++) add(read(), read());
}
void work() {
  for (register int i = 1; i <= q; i++) {
    int x = read(), y = read(), now = 0, ans = 0;
    while ((dep[y] - dep[x]) >= 256) upmax(ans, f[y][now]), ++now, y = jump[y];
    for (register int i = y; dep[i] >= dep[x]; i = fa[i])
      upmax(ans, a[i] ^ (now * 256 + (dep[y] - dep[i])));
    printf("%d\n", ans);
  }
}
int main() {
  pre();
  dfs(1);
  work();
  return 0;
}
