#include<bits/stdc++.h>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
int n;cin>>n;
int a[100010]={};int sum=0;
int b[100010]={};
for(int i=1;i<=n;i++){
cin>>a[i];sum+=a[i];
if(i!=n)
b[i+1]=sum;
else
b[1]=0;
}
int k;cin>>k;
for(int i=0;i<k;i++){
int start,end;
cin>>start>>end;
if(start>end){
int temp=start;
start=end;
end=temp;
}
int minsum=0;
minsum=min(b[end]-b[start],sum-(b[end]-b[start]));
printf("%d\n",minsum);
}
}