#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &x : A) cin >> x;
  vector<vector<int>> f(N, vector<int>(N));
  for (int i = 0; i < N; ++i) {
    f[i][i] = A[i];
  }
  for (int i = N - 1; i >= 0; --i) {
    for (int j = i + 1; j < N; ++j) {
      f[i][j] = f[i][j - 1] ^ f[i + 1][j];
    }
  }
  for (int i = N - 1; i >= 0; --i) {
    for (int j = i + 1; j < N; ++j) {
      f[i][j] = max({f[i][j], f[i + 1][j], f[i][j - 1]});
    }
  }
  0;
  int Q;
  cin >> Q;
  while (Q--) {
    int L, R;
    cin >> L >> R;
    --L, --R;
    cout << f[L][R] << "\n";
  }
}
