n = int(input())
a = list(map(int, input().split()))
q = int(input())
for _ in range(q):
l, r = map(int, input().split())
ans = 0
for i in range(l - 1, r):
sum = 0;
for j in range(i, r):
sum += a[j]
if sum == 0:
ans += 1
print(ans)