#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
long long ans[maxn][maxn];
long long val[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%I64d", &val[i]);
  for (int i = n - 1; i >= 0; i--) {
    ans[i][i] = val[i];
    for (int j = i + 1; j < n; j++) {
      ans[i][j] = ans[i][j - 1] ^ ans[i + 1][j];
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j < n; j++) {
      ans[i][j] = max(max(ans[i][j - 1], ans[i + 1][j]), ans[i][j]);
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%I64d\n", ans[l - 1][r - 1]);
  }
}
