#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long** tab = new long long*[n];
  for (int i = 0; i < n; ++i) tab[i] = new long long[n - i];
  long long** tab_max = new long long*[n];
  for (int i = 0; i < n; ++i) tab_max[i] = new long long[n - i];
  for (long long i = 0; i < n; ++i) {
    cin >> tab[0][i];
    tab_max[0][i] = tab[0][i];
  }
  for (long long i = 1; i < n; ++i) {
    for (long long j = 0; j < n - i; ++j) {
      tab[i][j] = tab[i - 1][j] ^ tab[i - 1][j + 1];
      tab_max[i][j] =
          max(tab[i][j], max(tab_max[i - 1][j], tab_max[i - 1][j + 1]));
    }
  }
  long long q;
  cin >> q;
  int l, r;
  for (long long i = 0; i < q; ++i) {
    cin >> l >> r;
    cout << tab_max[r - l][l - 1] << endl;
  }
  return 0;
}
