#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const long long inf = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 0, 1, -1, -1, 1};
int n, dp[5001][5001], ans[5001][5001], q, a[N];
inline int sum(int l, int r) {
  if (l > r) return 0;
  if (~dp[l][r]) return dp[l][r];
  if (l == r) return a[l];
  return dp[l][r] = (sum(l + 1, r) ^ sum(l, r - 1));
}
inline int Dp(int l, int r) {
  if (l > r) return 0;
  if (~ans[l][r]) return ans[l][r];
  return ans[l][r] = max(max(Dp(l + 1, r), Dp(l, r - 1)), sum(l, r));
}
inline void boost() {
  ios_base ::sync_with_stdio(NULL);
  cin.tie(NULL), cout.tie(NULL);
}
inline void Solve() {
  boost();
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  memset(ans, -1, sizeof(ans));
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << Dp(l, r) << '\n';
  }
}
int main() {
  int tt = 1;
  while (tt--) {
    Solve();
  }
  return 0;
}
