#include <stdio.h>
int getshortest(int from, int to, int *distance, int sum){
if(from > to){
int tmp = from;
from = to;
to = tmp;
} else if(from == to){
return 0;
}
int result1 = distance[to - 1] - ((from - 1 < 0) ? 0 : distance[from - 1]);
int result2 = sum - result1;
return (result1 < result2) ? result1 : result2;
}
int main(){
int M, N, i;
scanf("%d", &N);
int sum = 0, distance[N];
memset(distance, 0, sizeof(distance));
for(i = 0; i < N; i++){
int dis;
scanf("%d", &dis);
sum += dis;
distance[i] = sum;
}
scanf("%d", &M);
int result[M];
int demond[M][2];
for(i = 0; i < M; i++){
scanf("%d %d", &demond[i][0], &demond[i][1]);
}
for(i = 0; i < M; i++){
result[i] = getshortest(demond[i][0] - 1, demond[i][1] - 1, distance, sum);
}
for(i = 0; i < M; i++){
printf("%d\n", result[i]);
}
return 0;
}