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