n,m=list(map(int,input().split()))
dic1={}
for i in range(n):
xh,xm,cj=list(map(str,input().split()))
dic1[xh]=int(cj)
#print(dic1)
for i in range(m):
xhh=input()
score=dic1[xhh]
if score>=90:
print("A")
elif score>=80:
print("B")
elif score>=70:
print("C")
elif score>=60:
print("OK")
else:
print("ARE YOU PIG?")