#include <bits/stdc++.h>
using namespace std;
int a[5005], dp[5005][5005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], dp[i][i] = a[i];
  for (int j = 1; j < n; j++) {
    for (int i = 1; i <= n; i++) {
      dp[i][i + j] = dp[i][i + j - 1] ^ dp[i + 1][i + j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
  }
  for (int j = 1; j <= n; j++) {
    for (int i = j; i >= 1; i--) dp[i][j] = max(dp[i][j], dp[i + 1][j]);
  }
  int q, x, y;
  cin >> q;
  while (q--) {
    cin >> x >> y;
    cout << dp[x][y] << '\n';
  }
  return 0;
}
