while True:
try:
ans=list(map(int,input().split()))
x=int(input())
for i in range(x):
a=0
b=0
anscopy=ans
tries=list(map(int,input().split()))
for n in range(4):
print(anscopy[n],tries[n])
if anscopy[n]==tries[n]:
a+=1
tries[n]=-1
anscopy[n]=-1
anscopy_=set(anscopy)
tries_=set(tries)
if -1 in tries_:
tries_.remove(-1)
if -1 in anscopy_:
anscopy_.remove(-1)
b+=sum([y in anscopy_ for y in tries_])
print(a,"A",b,"B")
except EOFError:
break