#include <bits/stdc++.h>
using namespace std;
int ans[5005][5005];
int finans[5005][5005];
void solve() {
  memset(finans, -1, sizeof finans);
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int l = 1; l < n + 1; l++) {
    for (int i = 0; i < n - l + 1; i++) {
      int j = i + l - 1;
      if (j - i == 0) {
        ans[i][j] = x[i];
      } else {
        ans[i][j] = ans[i][j - 1] ^ ans[i + 1][j];
      }
    }
  }
  for (int l = 1; l <= n; l++) {
    for (int i = 0; i < n - l + 1; i++) {
      int j = i + l - 1;
      if (i == j)
        finans[i][j] = ans[i][j];
      else
        finans[i][j] = max({finans[i][j - 1], finans[i + 1][j], ans[i][j]});
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << finans[l - 1][r - 1] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
