#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 100;
array<int, N> a;
array<array<int, N>, N> cur, best;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) best[i][i] = cur[i][i] = a[i];
  for (int len = 2; len <= n; ++len) {
    for (int i = 1, j = i + len - 1; j <= n; ++i, ++j) {
      cur[i][j] = cur[i][j - 1] xor cur[i + 1][j];
      best[i][j] = max(max(best[i][j - 1], best[i + 1][j]), cur[i][j]);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int le, r;
    cin >> le >> r;
    cout << best[le][r] << '\n';
  }
}
