#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 100;
int n, q, l, r;
int num[maxn];
int ans[maxn][maxn];
int dp[maxn][maxn];
int main() {
  while (scanf("%d", &n) != EOF) {
    memset(ans, 0, sizeof(ans));
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &num[i]);
      dp[i][i] = num[i];
      ans[i][i] = num[i];
    }
    for (int i = 2; i <= n; ++i) {
      for (int j = 1; j <= n - i + 1; ++j) {
        ans[j][j + i - 1] = ans[j][j + i - 2] ^ ans[j + 1][j + i - 1];
        dp[j][j + i - 1] =
            max(ans[j][j + i - 1], max(dp[j][j + i - 2], dp[j + 1][j + i - 1]));
      }
    }
    scanf("%d", &q);
    while (q--) {
      scanf("%d%d", &l, &r);
      printf("%d\n", dp[l][r]);
    }
  }
  return 0;
}
