def score(s):
g=""
if s>=90:
g="A"
elif s>=80:
g="B"
elif s>=70:
g="C"
elif s>=60:
g="OK"
else:
g="ARE YOU PIG?"
return g
x,y=map(int,raw_input().strip().split())
list1=[]
for i in range(x):
rec=raw_input().strip().split()
n,m,s=rec[0],rec[1],int(rec[2])
list1.append([n,m,s])
list2=[]
for i in range(y):
a=raw_input()
list2.append(a)
for li2 in list2:
for j in range(x):
if li2==list1[j][0]:
print(score(list1[j][2]))