#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const long long inf = 1ll << 60;
const long long iinf = 2147483647;
const long long mod = 998244353;
const long long maxn = 1e3 + 5;
long long pw(long long x, long long p) {
  long long ret = 1;
  while (p > 0) {
    if (p & 1) {
      ret *= x;
      ret %= mod;
    }
    x *= x;
    x %= mod;
    p >>= 1;
  }
  return ret;
}
long long inv(long long x) { return pw(x, mod - 2); }
long long dp[5005][5005];
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> vc(n);
  for (long long i = (0); i < (n); i++) {
    cin >> vc[i];
  }
  for (long long i = (1); i < (n + 1); i++) {
    for (long long j = (1); j < (n - i + 1 + 1); j++) {
      if (i == 1) {
        dp[i][j] = vc[j - 1];
        continue;
      }
      dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1];
    }
  }
  for (long long i = (1); i < (n + 1); i++) {
    for (long long j = (1); j < (n - i + 1 + 1); j++) {
      dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i - 1][j + 1]});
    }
  }
  long long q;
  cin >> q;
  for (long long i = (0); i < (q); i++) {
    long long l, r;
    cin >> l >> r;
    cout << dp[r - l + 1][l] << '\n';
  }
}
