#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
using namespace std::chrono;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> vec(n, 0);
  for (auto &x : vec) cin >> x;
  vector<vector<long long int>> dp(n + 1, vector<long long int>(n + 1, 0));
  for (int i = 0; i < n; i++) dp[i][i] = vec[i];
  for (long long int gap = 1; gap < n; gap++) {
    for (int j = 0; j + gap < n; j++) {
      dp[j][j + gap] = dp[j][j + gap - 1] ^ dp[j + 1][j + gap];
    }
  }
  for (long long int gap = 1; gap < n; gap++) {
    for (int j = 0; j + gap < n; j++) {
      dp[j][j + gap] =
          max({dp[j][j + gap], dp[j][j + gap - 1], dp[j + 1][j + gap]});
    }
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int l, r;
    cin >> l >> r;
    l--;
    r--;
    cout << dp[l][r] << endl;
  }
  return 0;
}
