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