n=int(input())
re=0
for i in range(n):
w,s=map(int, input().strip().split())
re=re+w*s
if re>0 :
print(re)
else:
print(0)
n=int(input())
re=0
for i in range(n):
w,s=map(int, input().strip().split())
re=re+w*s
if re>0 :
print(re)
else:
print(0)