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