n = int(input())
arr = []
c = 0
for i in range(n):
a = int(input())
arr.append(a)
a = arr[i]
if a % 3 == 0 and len(str(a)) == 2:
c += 1
if i % 2 == 0:
a[i] = c
n = int(input())
arr = []
c = 0
for i in range(n):
a = int(input())
arr.append(a)
for i in range(n):
a = arr[i]
if a % 3 == 0 and len(str(a)) == 2:
c += 1
if i % 2 == 0:
a[i] = c