#include <bits/stdc++.h>
using namespace std;
int dp[5001][5001], maxi[5001][5001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> dp[i][i];
    maxi[i][i] = dp[i][i];
  }
  for (int k = 1; k < n; k++) {
    for (int i = 0; k + i < n; i++) {
      int j = k + i;
      dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j];
      maxi[i][j] = max(dp[i][j], max(maxi[i][j - 1], maxi[i + 1][j]));
    }
  }
  int q;
  cin >> q;
  for (int o = 0; o < q; o++) {
    int a, b;
    cin >> a >> b;
    cout << maxi[a - 1][b - 1] << '\n';
  }
  return 0;
}
