#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10, NX = 1e9 + 7;
int n, m, r, t, a, b, q, c, A[N][N], F[N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[n][i]);
  for (int i = n - 1; i; i--)
    for (int j = 1; j <= i; j++) A[i][j] = A[i + 1][j] ^ A[i + 1][j + 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++) F[j][j + n - i] = A[i][j];
  for (int i = 2; i <= n; i++) {
    for (int l = 1; l + i - 1 <= n; l++) {
      F[l][l + i - 1] =
          max(F[l][l + i - 1], max(F[l + 1][l + i - 1], F[l][l + i - 2]));
    }
  }
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", F[l][r]);
  }
  return (0);
}
