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