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