#这是答案
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):
i=d[input()]
if 90<=i<=100:
print("A")
elif 80<=i<90:
print("B")
elif 70<=i<80:
print("C")
elif 60<=i<70:
print("OK")
else:
print("ARE YOU PIG?")