#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
const long long int INF = 1e18 + 5;
const int inf = 2e9;
const int N = 5005;
const double eps = 1e-10;
const double PI = 3.14159265;
int dp[N][N], zor[N][N];
void solve() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) dp[i][1] = a[i], zor[i][1] = a[i];
  for (int len = 2; len <= n; len++) {
    for (int i = len; i <= n; i++) {
      zor[i][len] = zor[i][len - 1] ^ zor[i - 1][len - 1];
      dp[i][len] = max(zor[i][len], max(dp[i][len - 1], dp[i - 1][len - 1]));
    }
  }
  int q, l, r;
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << dp[r][r - l + 1] << '\n';
  }
  return;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
