x,y=map(int,input().split())
a={}
b={10:"A",9:"A",8:"B",7:"C",6:"OK"}
for i in range(x):
num,name,score=input().split()
a[num]=[name,int(score)]
for j in range(y):
sea_n=input()
t_score=a[sea_n][1]
if t_score//10<6:
print("ARE YOU PIG?")
else:
print(b[t_score//10])