#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, m, i, j;
  cin >> n;
  int arr[n];
  int dp[n][n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    dp[0][i] = arr[i];
  }
  for (i = 1; i < n; i++) {
    for (j = 0; j <= n - i; j++) {
      dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1];
    }
  }
  for (i = 1; i < n; i++) {
    for (j = 0; j < n - i; j++) {
      dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i - 1][j + 1]});
    }
  }
  int q;
  cin >> q;
  while (q--) {
    cin >> i >> j;
    i--;
    cout << dp[j - i - 1][i] << endl;
  }
}
