#include<stdio.h>
#include<algorithm>

using namespace std;

const int MAXN = 100005;

int d[MAXN],A[MAXN];        //d[i]用来存储沿顺时针方向第一个节点到第i个节点的距离,A[i]存储第i个节点到第i+1个节点的距离 

int main(){

    int n;
    scanf("%d",&n);

    int sum = 0;        //记录总距离 

    int left,right;

    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);

        sum += A[i];
        d[i] = sum;        //d[i]就是顺时针第1个节点到第i个节点后一个节点(i+1)的距离 
    }

     int m;

     scanf("%d",&m);

     for(int i=0;i<m;i++){
         scanf("%d %d",&left,&right);

         if(left>right)    swap(left,right);

         int distance = d[right-1] - d[left-1];

         printf("%d\n",min(distance,sum-distance));
     }





    return 0;
}