#include <bits/stdc++.h>
using namespace std;
int dpp[5005][5005];
int arr[5005];
int answer[5005][5005];
int reality[5005][5005];
int main() {
  int n, i, j, m, k, l;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
    dpp[i][1] = arr[i];
    answer[i][1] = dpp[i][1];
    reality[i][1] = dpp[i][1];
  }
  for (l = 2; l <= n; ++l) {
    for (i = 1; i <= n - l + 1; ++i) {
      dpp[i][l] = dpp[i][l - 1] ^ dpp[i + 1][l - 1];
    }
  }
  for (l = 2; l <= n; ++l) {
    for (i = 1; i <= n - l + 1; ++i) {
      answer[i][l] = max(answer[i][l - 1], dpp[i][l]);
    }
  }
  for (l = 2; l <= n; ++l) {
    for (i = 1; i <= n - l + 1; ++i) {
      reality[i][l] = max(answer[i][l], reality[i + 1][l - 1]);
    }
  }
  int q, r;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &l);
    scanf("%d", &r);
    printf("%lld\n", reality[l][r - l + 1]);
  }
  return 0;
}
