#include <bits/stdc++.h>
using namespace std;
using matrix = vector<vector<long long>>;
const int MAXN = 5050;
int a[MAXN], cnt[MAXN];
int dp[MAXN][MAXN];
int dp2[MAXN][MAXN];
vector<int> st[MAXN];
int getxor(int l, int r) {
  int len = r - l + 1;
  int ans = 0;
  for (int i : st[len]) {
    ans ^= a[l + i];
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  st[1] = {{0}};
  for (int i = 2; i < MAXN; ++i) {
    for (int j : st[i - 1]) {
      cnt[j]++;
      cnt[j + 1]++;
    }
    for (int j = 0; j < MAXN; ++j) {
      if (cnt[j] == 1) {
        st[i].push_back(j);
      }
      cnt[j] = 0;
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    dp[i][i] = getxor(i, i);
    for (int j = i + 1; j < n; ++j) {
      dp[i][j] = max(dp[i][j - 1], getxor(i, j));
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    int val = dp[i][i];
    dp2[i][i] = val;
    for (int j = i + 1; j < n; ++j) {
      val = max(val, dp[i][j]);
      dp2[i][j] = max(dp2[i + 1][j], val);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << dp2[l - 1][r - 1] << '\n';
  }
}
