#include <iostream>
using namespace std;
int main() {
int n;
scanf("%d", &n);
long long a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
long long summ[n + 1];
summ[0] = 0;
for (int i = 1; i < n + 1; i++) {
summ[i] = summ[i - 1] + a[i - 1];
}
int m;
scanf("%d", &m);
while (m--) {
int l, r;
scanf("%d", &l);
scanf("%d", &r);
printf("%d", summ[r] - summ[l - 1]);
printf("%s", "\n");
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IG47CiAgICBzY2FuZigiJWQiLCAmbik7CiAgICBsb25nIGxvbmcgYVtuXTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgc2NhbmYoIiVkIiwgJmFbaV0pOwogICAgfQogICAgbG9uZyBsb25nIHN1bW1bbiArIDFdOwogICAgc3VtbVswXSA9IDA7CiAgICBmb3IgKGludCBpID0gMTsgaSA8IG4gKyAxOyBpKyspIHsKICAgICAgICBzdW1tW2ldID0gc3VtbVtpIC0gMV0gKyBhW2kgLSAxXTsKICAgIH0KICAgIGludCBtOwogICAgc2NhbmYoIiVkIiwgJm0pOwogICAgd2hpbGUgKG0tLSkgewogICAgICAgIGludCBsLCByOwogICAgICAgIHNjYW5mKCIlZCIsICZsKTsKICAgICAgICBzY2FuZigiJWQiLCAmcik7CiAgICAgICAgcHJpbnRmKCIlZCIsIHN1bW1bcl0gLSBzdW1tW2wgLSAxXSk7CiAgICAgICAgcHJpbnRmKCIlcyIsICJcbiIpOwogICAgfQp9