#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], n;
int main()
{
scanf("%d", &n);
int x, tot = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", &x);
a[i] = a[i - 1] + x;
tot += x;
}
int m;
scanf("%d", &m);
while (m--)
{
int x, y;
scanf("%d%d", &x, &y);
if (x > y)swap(x, y);
printf("%d\n", min(a[y - 1] - a[x - 1], tot - (a[y - 1] - a[x - 1])));
}
return 0;
}