#include <iostream>
using namespace std;
const int N = 2e5 + 10;
int n, m, s[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++) cin >> s[i], s[i + n] = s[i]; //延长数据链
for (int i = 1; i <= 2*n; i ++) s[i] += s[i - 1]; //这就是前缀和数组,利用之前的空间
cin >> m;
while (m --)
{
int a, b;
cin >> a >> b;
if (a > b)
swap(a, b);
cout << min(s[b - 1] - s[a - 1], s[a + n - 1] - s[b - 1]) << endl;
}
}