#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<vector<ll> > cnt(n), ans(n);
  cnt.front().assign(n, 0);
  ans.front().assign(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> cnt.front()[i];
    ans.front()[i] = cnt.front()[i];
  }
  for (int i = 1; i < n; i++) {
    cnt[i].assign(n, 0);
    ans[i].assign(n, 0);
    for (int j = 0; j < n - i; j++) {
      cnt[i][j] = cnt[i - 1][j] ^ cnt[i - 1][j + 1];
      ans[i][j] = max({cnt[i][j], ans[i - 1][j], ans[i - 1][j + 1]});
    }
  }
  int m;
  cin >> m;
  while (m--) {
    int L, R;
    cin >> L >> R;
    cout << ans[R - L][L - 1] << endl;
  }
  return 0;
}
