#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 5000 + 20;
const int INF = 0x3f3f3f3f;
int n;
int a[N], dp[N][N];
int ans[N][N];
int main(int args, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    ans[i][1] = dp[i][1] = a[i];
  }
  for (int k = 2; k <= n; ++k) {
    for (int i = 1; i + k - 1 <= n; ++i) {
      dp[i][k] = dp[i][k - 1] ^ dp[i + 1][k - 1];
      ans[i][k] = max(dp[i][k], max(ans[i][k - 1], ans[i + 1][k - 1]));
    }
  }
  for (int i = 1; i <= n; ++i) ans[i][1] = dp[i][1];
  int l, r, q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d %d", &l, &r);
    printf("%d\n", ans[l][r - l + 1]);
  }
  return 0;
}
