#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int dp[N][N], n;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> dp[i][i];
  for (int len = 1; len <= n; len++)
    for (int i = len - 1; i; i--) dp[i][len] = dp[i + 1][len] ^ dp[i][len - 1];
  for (int len = 1; len <= n; len++)
    for (int i = len; i; i--)
      dp[i][len] = max(dp[i][len], max(dp[i][len - 1], dp[i + 1][len]));
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << dp[l][r] << "\n";
  }
}
