N = int(input())
number_list = [str(input()) for n in range(N)]
first_list = [n for n in number_list if n[0] == '3']
print(len(first_list))
N = int(input())
number_list = [str(input()) for n in range(N)]
first_list = [n for n in number_list if n[0] == '3']
print(len(first_list))