#include <bits/stdc++.h>
using namespace std;
int ara[5002][5002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ara[1][i];
  int len = n;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < len; j++) ara[i][j] = ara[i - 1][j] ^ ara[i - 1][j + 1];
    len--;
  }
  len = n;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < len; j++)
      ara[i][j] = max(ara[i][j], max(ara[i - 1][j], ara[i - 1][j + 1]));
    len--;
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    len = (r - l + 1);
    cout << ara[len][l] << endl;
  }
  return 0;
}
