a,b=map(int,input().split())
c=[]
for i in range(a):
c1=list(map(str,input().split()))
c.append(c1)
for j in range(b):
d=input()
for k in range(len(c)):
if c[k][0]==d:
e=int(c[k][2])
if e>=90 and e<=100:
print("A")
elif e>=80 and e<90:
print("B")
elif e>=70 and e<80:
print("C")
elif e>=60 and e<70:
print("OK")
elif e<60:
print("ARE YOU PIG?")