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