#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
//前缀和
const int N = 100010;
int n,m;
int s[N];
int main()
{
cin>>n;
for(int i = 1; i<=n; i++)
{
cin>>s[i];
s[i] += s[i-1];
}
cin>>m;
while(m--)
{
int l,r;
cin>>l>>r;
if(l>r) swap(l,r);
cout<<min(s[r-1]-s[l-1],s[n]-s[r-1]+s[l-1])<<endl;
}
return 0;
}