#include <bits/stdc++.h>
using namespace std;
long long a[5005], d[5005][5005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    d[i][i] = a[i];
  }
  for (int len = 2; len <= n; len++) {
    for (int start = 1; start + len <= n + 1; start++) {
      int end = start + len - 1;
      d[start][end] = d[start + 1][end] ^ d[start][end - 1];
    }
  }
  for (int len = 1; len <= n; len++) {
    for (int start = 1; start + len <= n + 1; start++) {
      int end = start + len - 1;
      d[start][end] =
          max(d[start][end], max(d[start + 1][end], d[start][end - 1]));
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << d[l][r] << endl;
  }
}
