#include <bits/stdc++.h>
using namespace std;
int n;
int a[5555];
int dp[5005][5005], res[5005][5005];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      if (!k)
        dp[i][i] = res[i][i] = a[i];
      else if (i + k < n) {
        dp[i][i + k] = dp[i][i + k - 1] ^ dp[i + 1][i + k];
        res[i][i + k] =
            max(res[i][i + k - 1], max(res[i + 1][i + k], dp[i][i + k]));
      }
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d", &l);
    scanf("%d", &r);
    printf("%d\n", res[l - 1][r - 1]);
  }
  return 0;
}
