#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using ld = long double;
mt19937 rnd(time(nullptr));
int Func(vector<int>& data, int l, int r) {
  int result = 0;
  int n = (r - l + 1) - 1;
  for (int i = l, k = 0; i <= r; i++, k++) {
    if ((n | k) == n) result ^= data[i];
  }
  return result;
}
inline void Solve() {
  int n = 0;
  cin >> n;
  vector<int> data(n);
  for (auto& it : data) cin >> it;
  vector<vector<int>> result(n, vector<int>(n));
  for (int l = 0; l <= n - 1; l++) result[l][l] = data[l];
  for (int k = 1; k <= n - 1; k++) {
    for (int l = 0, r = k; (l <= n - 1) && (r <= n - 1); l++, r++) {
      result[l][r] = result[l][r - 1] ^ result[l + 1][r];
    }
  }
  vector<vector<int>> prefix_max(n, vector<int>(n));
  for (int r = 0; r <= n - 1; r++) {
    prefix_max[r][r] = result[r][r];
    for (int l = r - 1; l >= 0; l--)
      prefix_max[r][l] = max(prefix_max[r][l + 1], result[l][r]);
  }
  vector<vector<int>> dp(n, vector<int>(n));
  for (int l = 0; l <= n - 1; l++) {
    dp[l][l] = prefix_max[l][l];
    for (int r = l + 1; r <= n - 1; r++)
      dp[l][r] = max(dp[l][r - 1], prefix_max[r][l]);
  }
  int q = 0;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l = 0, r = 0;
    cin >> l >> r;
    l--, r--;
    cout << dp[l][r] << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(20);
  Solve();
  return 0;
}
