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