#include <bits/stdc++.h>
using namespace std;
int dp[5000 + 1][5000 + 1];
int f[5000 + 1][5000 + 1];
int a[5000 + 1];
int N, Q;
int main() {
  int i, j, len;
  cin >> N;
  for (i = 1; i <= N; i++) cin >> a[i];
  for (i = 1; i <= N; i++) dp[i][i] = f[i][i] = a[i];
  for (len = 2; len <= N; len++)
    for (i = 1; i <= N - len + 1; i++) {
      j = i + len - 1;
      f[i][j] = f[i + 1][j] ^ f[i][j - 1];
      dp[i][j] = max(f[i][j], max(dp[i + 1][j], dp[i][j - 1]));
    }
  cin >> Q;
  while (Q--) {
    cin >> i >> j;
    cout << dp[i][j] << '\n';
  }
  return 0;
}
