n,m=map(int,input().split())
d={}
for tcase in range(n):
a=input().split()
d[a[0]]=int(a[2])
for tcase in range(m):
x=d[input()]
if x>=90:print("A")
elif x>=80:print("B")
elif x>=70:print("C")
elif x>=60:print("OK")
else: print("ARE YOU PIG?")