#include <bits/stdc++.h>
using namespace std;
const int N = 5003;
int n, q, l, r;
int a[N];
int dp[N][N];
int b[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 >> a[i];
    b[1][i] = a[i];
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= n - i + 1; ++j) {
      b[i][j] = b[i - 1][j] ^ b[i - 1][j + 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      dp[i][j] = b[j - i + 1][i];
    }
  }
  for (int len = 2; len <= n; ++len) {
    for (int i = 1; i <= n - len + 1; ++i) {
      int j = i + len - 1;
      dp[i][j] = max(max(dp[i + 1][j], dp[i][j - 1]), dp[i][j]);
    }
  }
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << dp[l][r] << '\n';
  }
}
