//前缀和,先预处理一下s[N],环形拆成一条直线
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100010;
int n,m;
int s[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&s[i]);
s[i]+=s[i-1];
}
scanf("%d", &m);
while (m -- )
{
int l, r;
scanf("%d%d", &l, &r);
if (l > r) swap(l, r);
printf("%d\n", min(s[r - 1] - s[l - 1], s[n] - s[r - 1] + s[l - 1]));
}
return 0;
}