#include <bits/stdc++.h>
using namespace std;
const int MAX = 5010;
int A[MAX];
int f[MAX][MAX];
int F[MAX][MAX];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  for (int l = 0; l < n; l++) {
    for (int i = 1; i + l <= n; i++) {
      if (l == 0)
        f[i][l] = A[i];
      else
        f[i][l] = f[i][l - 1] ^ f[i + 1][l - 1];
      F[i][l] = max(f[i][l], max(F[i][l - 1], F[i + 1][l - 1]));
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", F[l][r - l]);
  }
}
