#include <bits/stdc++.h>
using namespace std;
int n, q, a[5050], f[5050][5050], g[5050][5050];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = (1); i <= (n); ++i) cin >> a[i];
  for (int l = (n); l >= (1); --l) {
    f[l][l] = a[l];
    g[l][l] = a[l];
    for (int r = (l + 1); r <= (n); ++r) {
      f[l][r] = max(f[l + 1][r], f[l][r - 1]);
      g[l][r] = g[l][r - 1] ^ g[l + 1][r];
      f[l][r] = max(f[l][r], g[l][r]);
    }
  }
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int l, r;
    cin >> l >> r;
    cout << f[l][r] << '\n';
  }
}
