#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5;
const int M = 5e3 + 5;
int st[N], to[N << 1], nx[N << 1];
int ch[M][2], v[N][256], fa[N], a[N], d[N], top[N];
int n, q, tot;
inline int read() {
  int x = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x;
}
inline void add(int u, int v) {
  to[++tot] = v, nx[tot] = st[u], st[u] = tot;
  to[++tot] = u, nx[tot] = st[v], st[v] = tot;
}
inline void dfs(int x) {
  d[x] = d[fa[x]] + 1;
  for (int i = st[x]; i; i = nx[i])
    if (to[i] != fa[x]) fa[to[i]] = x, dfs(to[i]);
  if (d[x] < 256) return;
  int now = x;
  memset(ch, 0, sizeof(ch)), tot = 0;
  while (d[x] - d[now] < 256) {
    int p = 0, val = a[now] ^ (d[x] - d[now]);
    for (int i = 16; ~i; --i) {
      int c = (val & (1 << i)) ? 1 : 0;
      if (!ch[p][c]) ch[p][c] = ++tot;
      p = ch[p][c];
    }
    now = fa[now];
  }
  top[x] = now;
  for (int i = 0; i < 256; ++i) {
    int all = 0, val = i * 256, p = 0;
    for (int j = 16; ~j; --j) {
      int c = (val & (1 << j)) ? 0 : 1;
      if (!ch[p][c])
        c ^= 1;
      else
        all += 1 << j;
      p = ch[p][c];
    }
    v[x][i] = all;
  }
}
int main() {
  n = read(), q = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i < n; ++i) add(read(), read());
  dfs(1);
  while (q--) {
    int x = read(), y = read(), ans = 0, cnt = 0, fir = y;
    while (d[y] - d[x] >= 256) ans = max(ans, v[y][cnt]), ++cnt, y = top[y];
    while (d[y] >= d[x]) ans = max(ans, a[y] ^ (d[fir] - d[y])), y = fa[y];
    printf("%d\n", ans);
  }
  return 0;
}
