N = int(input())
number_list = [str(input()) for i in range(N)]
start_three = [number for number in number_list if number[0] == '3']
print(len(start_three))
N = int(input())
number_list = [str(input()) for i in range(N)]
start_three = [number for number in number_list if number[0] == '3']
print(len(start_three))