#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int ceil1(int n, int k) {
  if (n % k) return n / k + 1;
  return n / k;
}
int pow1(int n, int k) {
  int ans = 1;
  while (k != 0) {
    if (k % 2) ans = (ans * n) % mod;
    n = (n * n) % mod;
    k = k / 2;
  }
  return ans;
}
bool ispal(string s) {
  int i = 0;
  int j = s.size() - 1;
  while (i < j) {
    if (s[i] != s[j]) return false;
    i++;
    j--;
  }
  return true;
}
int gcdd(int a, int b) {
  if (b == 0) return a;
  return gcdd(b, a % b);
}
int fact(int n) {
  if (n == 1 || n == 0)
    return 1;
  else
    return (n * fact(n - 1)) % mod;
}
bool isprime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int f[5500][5500];
int dp[5500][5500];
void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 2);
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(dp, 0, sizeof(dp));
  memset(f, 0, sizeof(f));
  for (int i = n; i >= 1; i--) {
    for (int j = i; j <= n; j++) {
      if (i == j)
        f[i][j] = a[i];
      else
        f[i][j] = f[i + 1][j] ^ f[i][j - 1];
      dp[i][j] = max(f[i][j], dp[i + 1][j]);
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << dp[l][r] << endl;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  while (q--) {
    solve();
  }
  return 0;
}
