#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5678;
int dp[MAXN][MAXN];
int a[MAXN], dp2[MAXN][MAXN];
int dfs(int l, int r) {
  if (dp[l][r] != -1) return dp[l][r];
  if (l == r) return dp[l][r] = a[l];
  return dp[l][r] = dfs(l, r - 1) ^ dfs(l + 1, r);
}
int dfs2(int l, int r) {
  if (dp2[l][r] != -1) return dp2[l][r];
  if (l == r) return dp2[l][r] = a[l];
  return dp2[l][r] = max({dp[l][r], dfs2(l, r - 1), dfs2(l + 1, r)});
}
int main() {
  int n, q, l, r;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) dp[i][j] = dp2[i][j] = -1;
  dfs(1, n);
  dfs2(1, n);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    printf("%d\n", dp2[l][r]);
  }
}
