#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n, d, k, ina, inb, sum = 0, a, b;
scanf ("%d", &n);
v.resize(n + 1);
for (int i = 0; i < n; i++) {
scanf ("%d", &d);
v[i + 1] = d;
sum += d;
}
// cout << sum << endl;
scanf ("%d", &k);
for (int i = 0; i < k; i++) {
int temp = 0;
scanf ("%d %d", &ina, &inb);
a = max(ina, inb); b = min(ina, inb);
int span = a - b;
if (span < n - span) { //从小序号到大序号
for (int j = b; j < a; j++)
temp += v[j];
temp = min (temp, sum - temp);
}
else {
for (int j = a; j <= n; j++)
temp += v[j];
for (int j = 1; j < b; j++)
temp += v[j];
temp = min (temp, sum - temp);
}
printf ("%d\n", temp);
}
}