#include <bits/stdc++.h>
using namespace std;
int N;
int A[5005];
int DP[5005][5005];
void Read() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
}
void precalcDP() {
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++) DP[i][j - i] = A[j];
    for (int k = 0; (1 << k) <= N; k++)
      for (int j = 0; j < N; j++)
        if ((j & (1 << k)) != 0) DP[i][j] ^= DP[i][j ^ (1 << k)];
  }
  for (int j = 1; j <= N; j++) {
    for (int i = 1; j + i <= N; i++)
      DP[i][j] = max(DP[i][j], max(DP[i][j - 1], DP[i + 1][j - 1]));
  }
}
void Query(int a, int b) {
  int dist = b - a;
  printf("%d\n", DP[a][dist]);
}
int main() {
  Read();
  precalcDP();
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    Query(x, y);
  }
  return 0;
}
