#include <bits/stdc++.h>
using namespace std;
int n, i, j, q, st, dr;
long long Dp[5005][5005], A[5005];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> A[i];
    Dp[i][i] = A[i];
  }
  for (i = n - 1; i >= 1; i--)
    for (j = i + 1; j <= n; j++) Dp[i][j] = Dp[i][j - 1] ^ Dp[i + 1][j];
  for (i = n - 1; i >= 1; i--)
    for (j = i + 1; j <= n; j++)
      Dp[i][j] = max(Dp[i][j], max(Dp[i + 1][j], Dp[i][j - 1]));
  cin >> q;
  for (i = 1; i <= q; i++) {
    cin >> st >> dr;
    cout << Dp[st][dr] << "\n";
  }
  return 0;
}
