#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int arr[maxn];
int dp[maxn][maxn];
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &dp[1][i]);
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      dp[i][j] = dp[i - 1][j - 1] ^ dp[i - 1][j];
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      dp[i][j] = max({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j]});
    }
  }
  scanf("%d", &q);
  int l, r;
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &l, &r);
    printf("%d\n", dp[r - l + 1][r]);
  }
  return 0;
}
