#include <bits/stdc++.h>
using namespace std;
void OUT_TST(string s, istream_iterator<string> it) { cerr << s; }
template <typename T, typename... Args>
void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " ";
  OUT_TST(s, ++it, args...);
}
template <class T>
void rd(T& ret) {
  ret = 0;
  bool ok = 0, u = 0;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + (ret << 1) + c - '0', ok = 1;
    else if (c == '-')
      u = 1;
    else if (ok) {
      if (u) ret *= -1;
      return;
    }
  }
}
long long powmod(long long p, long long n, long long mod) {
  long long ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * p % mod;
    p = p * p % mod;
  }
  return ret;
}
template <class T>
bool chmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int N = 5005;
const int M = (int)1e5 + 9;
int dp[N][N], f[N], ans[M];
vector<pair<int, int> > qn[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) scanf("%d", &dp[i][i]);
  for (int l = (2); l < (n + 1); l++) {
    for (int i = 0, j = l - 1; j < n; ++i, ++j) {
      dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j];
    }
  }
  int q;
  scanf("%d", &q);
  for (int i = (0); i < (q); i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l;
    --r;
    qn[r].emplace_back(-l, i);
  }
  for (int i = (0); i < (n); i++) sort((qn[i]).begin(), (qn[i]).end());
  for (int r = (0); r < (n); r++) {
    int mx = 0;
    auto it = qn[r].begin();
    for (int l = (r + 1) - 1; l >= (0); l--) {
      chmax(f[l], dp[l][r]);
      chmax(mx, f[l]);
      while (it != qn[r].end() && it->first == -l) {
        ans[it->second] = mx;
        ++it;
      }
    }
  }
  for (int i = (0); i < (q); i++) printf("%d\n", ans[i]);
  return 0;
}
