#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
int f[N][N];
int n;
int a[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> a[i], f[i][i] = a[i];
  for (int k = (1); k <= (n - 1); k++)
    for (int i = 1; i + k <= n; i++) {
      int j = i + k;
      f[i][j] = f[i][j - 1] ^ f[i + 1][j];
    }
  for (int k = (1); k <= (n - 1); k++)
    for (int i = 1; i + k <= n; i++) {
      int j = i + k;
      f[i][j] = max(max(f[i][j - 1], f[i + 1][j]), f[i][j]);
    }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int l, r;
    cin >> l >> r;
    cout << f[l][r] << endl;
  }
}
