#include<iostream>
#include<cstdio>
long long n,m,x,y;
long long a[10005];
inline long long read()
{
long long s=0,w=1;
char ch=getchar();
while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
int main()
{ freopen("climb.in","r",stdin);
freopen("climb.out","w",stdout);
n=read();
for(int i=0;i<=n;i++)
{
a[i]=read();
}
m=read();
for(int j=1;j<=m;j++)
{ long long maxn=0;
x=read();y=read();
for(int k=x;k<=y;k++)
if(a[k]>maxn) maxn=a[k];
printf("%lld",maxn);
}
return 0;
}