#include <bits/stdc++.h>
using namespace std;
const int _ = 1e2;
const int W = (1 << 8);
const int maxn = 1e5 + _;
const int maxW = W + 10;
struct trnode {
  int w[2], c;
} tr[maxW * maxW];
int trlen;
int newnode() {
  trlen++;
  tr[trlen].w[0] = tr[trlen].w[1] = tr[trlen].c = 0;
  return trlen;
}
void insert(int d, int g) {
  int now = 0;
  for (int i = 7; i >= 0; i--) {
    int x = (d >> i) & 1;
    if (!tr[now].w[x]) tr[now].w[x] = newnode();
    now = tr[now].w[x];
  }
  tr[now].c = max(tr[now].c, g);
}
int getmax(int d) {
  int ans = 0, now = 0;
  for (int i = 7; i >= 0; i--) {
    int x = ((d >> i) & 1) ^ 1;
    if (tr[now].w[x])
      ans |= (1 << i), now = tr[now].w[x];
    else
      now = tr[now].w[x ^ 1];
  }
  return ans * W + tr[now].c;
}
int a[maxn], fa[25][maxn];
int f[maxW][maxn];
void prework(int x) {
  trlen = -1;
  newnode();
  for (int i = 0, u = x; i < W; i++, u = fa[0][u])
    insert(a[u] / W, (a[u] & (W - 1)) ^ i);
  for (int i = 0; i < W; i++) f[i][x] = getmax(i);
}
struct node {
  int y, next;
} aa[2 * maxn];
int len, last[maxn];
void ins(int x, int y) {
  aa[++len].y = y;
  aa[len].next = last[x];
  last[x] = len;
}
int dep[maxn];
void dfs(int x) {
  if (x == 261) {
    int o;
    o++;
  }
  if (dep[x] >= W) prework(x);
  for (int i = 1; (1 << i) < dep[x]; i++) fa[i][x] = fa[i - 1][fa[i - 1][x]];
  for (int k = last[x]; k; k = aa[k].next) {
    int y = aa[k].y;
    if (y != fa[0][x]) {
      fa[0][y] = x;
      dep[y] = dep[x] + 1;
      dfs(y);
    }
  }
}
void solve(int x, int y) {
  int ans = 0, k = -1;
  while (dep[y] - dep[x] + 1 >= W) {
    k++;
    ans = max(ans, f[k][y]);
    y = fa[8][y];
  }
  if (dep[y] >= dep[x]) {
    k = (k + 1) * W - 1;
    while (y != fa[0][x]) {
      k++;
      ans = max(ans, k ^ a[y]);
      y = fa[0][y];
    }
  }
  printf("%d\n", ans);
}
int main() {
  int n, Q, x, y;
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    ins(x, y), ins(y, x);
  }
  dep[1] = 1;
  dfs(1);
  int t = 0;
  while (Q--) {
    scanf("%d%d", &x, &y);
    solve(x, y);
    t++;
  }
  return 0;
}
