#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7, LINF = 1e16 + 1;
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll P1 = 31, P2 = 37, M1 = 1e9 + 7, M2 = 1e9 + 9;
const int N = 5002, Q = 1e5 + 1;
int n, q, a[N], s[N], f[N][N], mx[N], res[Q];
vector<pair<int, int>> queries[N];
void computef() {
  for (int i = (int)1; i <= (int)n; ++i) f[i][i] = a[i];
  for (int len = (int)2; len <= (int)n; ++len) {
    for (int i = (int)1; i <= (int)n - len + 1; ++i) {
      int j = i + len - 1;
      f[i][j] = f[i][j - 1] ^ f[i + 1][j];
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> n;
  for (int i = (int)1; i <= (int)n; ++i) {
    cin >> a[i];
    s[i] = s[i - 1] ^ a[i];
  }
  cin >> q;
  for (int i = (int)0; i <= (int)q - 1; ++i) {
    int l, r;
    cin >> l >> r;
    queries[r].emplace_back(l, i);
  }
  computef();
  for (int i = (int)1; i <= (int)n; ++i) {
    for (int j = (int)i; j >= (int)1; --j) {
      mx[j] = max(mx[j + 1], mx[j]);
      mx[j] = max(f[j][i], mx[j]);
    }
    for (auto &p : queries[i]) {
      res[p.second] = max(mx[p.first], res[p.second]);
    }
  }
  for (int i = (int)0; i <= (int)q - 1; ++i) cout << res[i] << '\n';
}
