while True:
try:
o=0
p=0
a,b,c,d=map(int,input().split())
list2 = [a, b, c, d]
n=int(input())
for k in range(n):
w,x,y,z=map(int,input().split())
list2 = [a, b, c, d]
o=0
p=0
if w==a and w in list2:
o+=1
list2.remove(a)
if x==b and x in list2:
o+=1
list2.remove(b)
if y==c and y in list2:
o+=1
list2.remove(c)
if z in list2 and z==d:
o+=1
list2.remove(d)
if w in list2:
p+=1
list2.remove(w)
if x in list2:
p+=1
list2.remove(x)
if y in list2:
p+=1
list2.remove(y)
if z in list2:
p+=1
list2.remove(z)
print(o,end="")
print(str('A'),end="")
print(p,end="")
print(str('B'))
except:
break