#include <bits/stdc++.h>
using namespace std;
const long long int mod = 998244353ll;
const long long int P = 1000000007ll;
const long long int N = 5005ll;
long long int a[N][N];
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = (1); i <= (n); ++i) cin >> a[1][i];
  for (long long int i = (2); i <= (n); ++i)
    for (long long int j = (1); j <= (n - i + 1); ++j)
      a[i][j] = a[i - 1][j] ^ a[i - 1][j + 1];
  for (long long int i = (2); i <= (n); ++i)
    for (long long int j = (1); j <= (n - i + 1); ++j)
      a[i][j] = max(a[i][j], max(a[i - 1][j], a[i - 1][j + 1]));
  long long int q;
  cin >> q;
  while (q--) {
    long long int l, r;
    cin >> l >> r;
    cout << a[r - l + 1][l] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
