a,b=map(int,raw_input().strip().split())
dictxs={}
for i in range(a):
s1,s2,s3=map(str,raw_input().strip().split())
dictxs[s1]=int(s3)
list1=[]
for i in range(b):
list1.append(raw_input().strip())
for i in range(b):
num=dictxs[list1[i]]
if num>=90 and num<=100:
print 'A'
if num>=80 and num<90:
print 'B'
if num>=70 and num<80:
print 'C'
if num>=60 and num<70:
print 'OK'
if num<60:
print 'ARE YOU PIG?'