#include<cstdio>
#include<algorithm>

using namespace std;

int main(){

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

    int sum = 0;
    int d[100005] = {0};

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

    int left,right;
    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;
}