#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 7;
int a[MAXN], dp[MAXN][MAXN];
int main() {
  int n, T, l, r;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) dp[i][i] = a[i];
  for (int j = 1; j < n; j++) {
    for (int i = 1; i + j <= n; i++) {
      dp[i][i + j] = dp[i][i + j - 1] ^ dp[i + 1][i + j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
    }
  }
  for (int j = n; j >= 1; j--) {
    for (int i = j - 1; i >= 1; i--) {
      dp[i][j] = max(dp[i][j], dp[i + 1][j]);
    }
  }
  cin >> T;
  while (T--) {
    scanf("%d%d", &l, &r);
    printf("%d\n", dp[l][r]);
  }
  return 0;
}
