#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[5005], dp[5005][5005];
int main() {
  while (cin >> n) {
    memset(a, 0, sizeof(a));
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      dp[i][i] = a[i];
    }
    for (int i = n; i >= 1; i--) {
      for (int j = i + 1; j <= n; j++) {
        dp[i][j] = dp[i + 1][j] ^ dp[i][j - 1];
      }
    }
    for (int i = n; i >= 1; i--) {
      for (int j = i + 1; j <= n; j++) {
        dp[i][j] = max(dp[i][j], max(dp[i][j - 1], dp[i + 1][j]));
      }
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
      int l, r;
      cin >> l >> r;
      cout << dp[l][r] << endl;
    }
  }
  return 0;
}
