#include <bits/stdc++.h>
using namespace std;
int val[5010][5010], dp[5010][5010], a[5010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    val[i][i] = dp[i][i] = a[i];
  }
  for (int len = 2; len <= n; len++) {
    for (int l = 1; l + len - 1 <= n; l++) {
      int r = l + len - 1;
      val[l][r] = val[l][r - 1] ^ val[l + 1][r];
      dp[l][r] = max(max(dp[l][r - 1], dp[l + 1][r]), val[l][r]);
    }
  }
  int q, l, r;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &l, &r);
    printf("%d\n", dp[l][r]);
  }
  return 0;
}
