#include <bits/stdc++.h>
int n, m, k, l, a[5010], dp[5010][5010], g[5010][5010];
void bfs_dp(int l, int r) {
  if (l == r) {
    dp[l][r] = g[l][r] = a[l];
    return;
  }
  if (g[l][r - 1] == -1) bfs_dp(l, r - 1);
  if (g[l + 1][r] == -1) bfs_dp(l + 1, r);
  dp[l][r] = g[l][r] = (g[l][r - 1] ^ g[l + 1][r]);
  if (dp[l][r - 1] > dp[l][r]) dp[l][r] = dp[l][r - 1];
  if (dp[l + 1][r] > dp[l][r]) dp[l][r] = dp[l + 1][r];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  memset(g, -1, sizeof(g));
  memset(dp, -1, sizeof(dp));
  bfs_dp(0, n - 1);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &k, &l);
    printf("%d\n", dp[k - 1][l - 1]);
  }
  return 0;
}
