#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, fl = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - '0');
  return x * fl;
}
const int NN = 100000 + 17;
const int MM = 300 + 17;
void open() {
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
}
int a[NN];
int ks;
int dep[NN], fa[NN], ksf[NN];
int f[MM][NN];
int ch[MM * 20][2];
int tot;
vector<int> e[NN];
void ins(int val) {
  int x = 0;
  for (int k = 20; k >= 0; k--) {
    int typ = (val & (1 << k)) > 0;
    if (!ch[x][typ]) ch[x][typ] = ++tot;
    x = ch[x][typ];
  }
}
int query(int val) {
  int x = 0, res = 0;
  for (int k = 20; k >= 0; k--) {
    int typ = (val & (1 << k)) > 0;
    if (ch[x][typ ^ 1]) {
      x = ch[x][typ ^ 1];
      res += (1 << k);
    } else {
      x = ch[x][typ];
    }
  }
  return res;
}
void clear() {
  for (int i = 0; i <= tot; i++) ch[i][0] = ch[i][1] = 0;
  tot = 0;
}
void dfs(int x, int ff) {
  dep[x] = dep[ff] + 1;
  fa[x] = ff;
  if (dep[x] >= ks) {
    int y = x;
    while (dep[y] > dep[x] - ks) {
      ins((dep[x] - dep[y]) ^ a[y]);
      y = fa[y];
    }
    ksf[x] = y;
    for (int i = 0; i <= ks; i++) f[i][x] = query(i << 8);
    clear();
  }
  for (int i = 0, top = e[x].size(); i < top; i++) {
    int y = e[x][i];
    if (y != ff) dfs(y, x);
  }
}
int main() {
  int n = read(), q = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    e[x].push_back(y);
    e[y].push_back(x);
  }
  ks = 256;
  dfs(1, 0);
  while (q--) {
    int y = read(), x = read();
    int d = dep[x], h = 0, ans = 0;
    while (ksf[x] && dep[x] - ks + 1 >= dep[y]) {
      ans = max(ans, f[h][x]);
      x = ksf[x];
      h++;
    }
    while (dep[x] >= dep[y]) {
      ans = max(ans, (d - dep[x]) ^ a[x]);
      x = fa[x];
    }
    printf("%d\n", ans);
  }
  return 0;
}
