#include <bits/stdc++.h>
using namespace std;
int A[5010][5000];
int D[5010][5000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &D[0][i]), A[0][i] = D[0][i];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      A[i][j] = D[i][j] = D[i - 1][j] ^ D[i - 1][j + 1];
      A[i][j] = max(max(A[i - 1][j], A[i - 1][j + 1]), A[i][j]);
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    cout << A[r - l][l - 1] << '\n';
  }
}
