#include <bits/stdc++.h>
using namespace std;
const int N = 5123;
int xr[N][N];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    xr[i][1] = a[i];
  }
  for (int len = 2; len <= n; ++len) {
    for (int i = 1; i < n; ++i) {
      xr[i][len] = xr[i][len - 1] ^ xr[i + 1][len - 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      xr[i][j] = max(xr[i][j], xr[i][j - 1]);
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    int ans = 0;
    for (int i = l; i <= r; ++i) {
      ans = max(ans, xr[i][r - i + 1]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
