n = int(input())
sum = 0
for i in range(n):
___x = int(input())
___if(x % 3 == 0):
sum = sum + x
print(sum)
n = int(input())
sum = 0
for i in range(n):
___x = int(input())
___if(x % 3 == 0):
sum = sum + x
print(sum)