#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 1e5 + 500;
const int mod = 1e9 + 7;
const int inf = 1e9 + 500;
const int rad = 256;
int a[maxn];
int h[maxn];
int sqr[maxn][rad + 5];
int par[maxn];
int radpar[maxn];
bool vis[maxn];
int r[rad * 16][2];
int po;
vector<int> ger[maxn];
void add(int a) {
  int p = 1;
  for (int i = 16; i >= 0; i--) {
    bool bit = ((a >> i) & 1);
    if (r[p][bit] == -1) {
      r[p][bit] = po;
      po++;
    }
    p = r[p][bit];
  }
}
int finds(int a) {
  int p = 1;
  int ans = 0;
  for (int i = 16; i >= 0; i--) {
    bool bit = ((a >> i) & 1);
    ans *= 2;
    if (r[p][!bit] != -1) {
      p = r[p][!bit];
      ans++;
    } else {
      p = r[p][bit];
    }
  }
  return ans;
}
void dfs(int a) {
  vis[a] = 1;
  for (int i = 0; i < (int)ger[a].size(); i++) {
    int v = ger[a][i];
    if (vis[v] == 0) {
      h[v] = h[a] + 1;
      dfs(v);
    } else {
      par[a] = v;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    ger[u].push_back(v);
    ger[v].push_back(u);
  }
  par[0] = 0;
  dfs(0);
  for (int i = 0; i < n; i++) {
    memset((&r[0][0]), -1, 2 * rad * 16 * sizeof(int));
    po = 2;
    int pa = i;
    for (int j = 0; j < rad; j++) {
      add(a[pa] ^ (h[i] - h[pa]));
      if (pa == 0) {
        break;
      }
      pa = par[pa];
    }
    radpar[i] = pa;
    for (int j = 0; j < rad + 5; j++) {
      sqr[i][j] = finds(rad * j);
    }
  }
  for (int qw = 0; qw < q; qw++) {
    int ans = 0;
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    swap(v, u);
    int t = 0;
    int vv = v;
    while (h[radpar[vv]] >= h[u]) {
      ans = max(ans, sqr[vv][t]);
      t++;
      vv = radpar[vv];
      if (vv == 0) {
        break;
      }
    }
    while (vv != u) {
      ans = max(a[vv] ^ (h[v] - h[vv]), ans);
      vv = par[vv];
    }
    ans = max(ans, a[u] ^ (h[v] - h[u]));
    cout << ans << endl;
  }
}
