#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int a[5005];
int dp[5005][5005];
int f[5005][5005];
void dfs(int l, int k) {
  if (dp[l][k] >= 0) return;
  if (k == 1) {
    f[l][k] = a[l];
    dp[l][k] = a[l];
    return;
  }
  dfs(l + 1, k - 1);
  dfs(l, k - 1);
  f[l][k] = f[l + 1][k - 1] ^ f[l][k - 1];
  dp[l][k] = max(max(dp[l + 1][k - 1], dp[l][k - 1]), f[l][k]);
}
int main() {
  memset(dp, 128, sizeof(dp));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  dfs(1, n);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", dp[l][r - l + 1]);
  }
  return 0;
}
