#include <bits/stdc++.h>
using namespace std;
int n, V[5005], M[5005][5005], q, l, r;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> V[i];
    M[i][i] = V[i];
  }
  for (int j = 2; j <= n; j++)
    for (int i = 1; j + i - 1 <= n; i++)
      M[i][j + i - 1] = M[i][j + i - 2] ^ M[i + 1][j + i - 1];
  for (int i = n; i >= 1; i--)
    for (int j = i; j <= n; j++)
      M[i][j] = max(M[i][j], max(M[i][j - 1], M[i + 1][j]));
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << M[l][r] << '\n';
  }
  return 0;
}
