n,m=map(int,input().split())
dic={}
dic1={10:"A",9:"A",8:"B",7:"C",6:"OK"}
for i in range(n):
num,name,score=input().split()
dic[num]=[name,int(score)]
for j in range(m):
num1=input()
score1=dic[num1][1]
if score1//10<6:
print("ARE YOU PIG?")
else:
print(dic1[score1//10])