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