#include <bits/stdc++.h>
using namespace std;
int N, A[5005][5005], D[5005][5005];
int main() {
  int u, v, Q;
  scanf("%d", &N);
  for (register int i = 1; i <= N; i++) {
    scanf("%d", &A[i][1]);
    D[i][1] = A[i][1];
  }
  for (register int i = 2; i <= N; i++)
    for (register int j = 1; j <= N - i + 1; j++)
      A[j][i] = A[j][i - 1] ^ A[j + 1][i - 1];
  for (register int i = 2; i <= N; i++)
    for (register int j = 1; j <= N - i + 1; j++) {
      D[j][i] = ((D[j][i - 1]) > (D[j + 1][i - 1]) ? (D[j][i - 1])
                                                   : (D[j + 1][i - 1]));
      ((D[j][i]) < (A[j][i]) ? (D[j][i]) = (A[j][i]), 1 : 0);
    }
  scanf("%d", &Q);
  for (register int i = 1; i <= Q; i++) {
    scanf("%d%d", &u, &v);
    printf("%d\n", D[u][v - u + 1]);
  }
  return 0;
}
