#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b, long long int c) {
  long long int mx = a;
  if (mx < b) {
    mx = b;
  }
  if (mx < c) {
    mx = c;
  }
  return mx;
}
void disp(vector<vector<long long int> > arr) {
  for (auto itr : arr) {
    for (auto ittr : itr) {
      cout << ittr << " ";
    }
    cout << endl;
  }
}
int main() {
  long long int n;
  cin >> n;
  vector<vector<long long int> > arr(n);
  for (long long int i = 0; i < n; ++i) {
    arr[i] = vector<long long int>(n - i);
  }
  for (long long int i = 0; i < n; ++i) {
    cin >> arr[0][i];
  }
  for (long long int i = 1; i < n; ++i) {
    for (long long int j = 0; j < n - i; ++j) {
      arr[i][j] = arr[i - 1][j] ^ arr[i - 1][j + 1];
    }
  }
  for (long long int i = 1; i < n; ++i) {
    for (long long int j = 0; j < n - i; ++j) {
      arr[i][j] = max(arr[i - 1][j], arr[i - 1][j + 1], arr[i][j]);
    }
  }
  long long int q;
  cin >> q;
  long long int lf, rt;
  while (q--) {
    cin >> lf >> rt;
    lf--;
    rt--;
    cout << arr[rt - lf][lf] << endl;
  }
  return 0;
}
