x,y=map(int,raw_input().strip().split())
cj=[]
cx=[]
for i in range(x):
n,m,s=map(str,raw_input().strip().split())
cj.append([n,m,s])
for i in range(y):
cx.append(raw_input())
for j in cj:
if cx[i]==j[0] and 90<=int(j[2]):
score= "A"
elif cx[i]==j[0] and 80<=int(j[2]):
score= "B"
elif cx[i]==j[0] and 70<=int(j[2]):
score= "C"
elif cx[i]==j[0] and 60<=int(j[2]):
score= "OK"
elif cx[i]==j[0] and 60>int(j[2]):
score= "ARE YOU PIG?"
print score