while True:
try:
a,b,c,d=map(int,input().split())
t=[a,b,c,d]
n=int(input())
for i in range(n):
s=[int(x) for x in input().split()]
a=0
b=0
for i in range(n):
c=t.count(s[i])
if s[i]==t[i]:
a=a+1
c=t.count(s[i])-1
if (s[i]!=t[i]) and (s[i] in t) and (s.count(s[i])==c) :
b=b+1
print(a,end="")
print("A",end="")
print(b,end="")
print("B")
except:
break