#include <bits/stdc++.h>
using namespace std;
void zanj0() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long int n;
  cin >> n;
  vector<vector<long long int> > dp(n + 1, vector<long long int>(n + 1));
  vector<long long int> v(n + 1);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
    dp[1][i] = v[i];
  }
  for (long long int l = 2; l <= n; l++) {
    for (long long int i = 0; i < n; i++) {
      dp[l][i] = dp[l - 1][i] ^ dp[l - 1][i + 1];
    }
  }
  for (long long int l = 2; l <= n; l++) {
    for (long long int i = 0; i < n; i++) {
      dp[l][i] = max({dp[l - 1][i], dp[l][i], dp[l - 1][i + 1]});
    }
  }
  long long int q;
  cin >> q;
  long long int l, r;
  while (q--) {
    cin >> l >> r;
    long long int len = r - l + 1;
    l--;
    cout << dp[len][l] << endl;
  }
}
int main() {
  zanj0();
  solve();
  return 0;
}
