#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
const double pi = acos(-1.0), eps = 1e-9;
const long long INF = 1e18;
int n, a[N], b[5111][5111], q;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i], b[i][i] = a[i];
  for (int i = 1; i < n; ++i)
    for (int j = 1; j + i <= n; ++j)
      b[j][j + i] = (b[j][j + i - 1] ^ b[j + 1][j + i]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j + i - 1 <= n; ++j)
      b[j][j + i] = max(b[j][j + i], b[j][j + i - 1]),
               b[j - 1][j + i - 1] = max(b[j - 1][j + i - 1], b[j][j + i - 1]);
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << b[l][r] << endl;
  }
  return 0;
}
