dic = {10:'A',9:'A',8:'B',7:'C',6:'OK'}
x,y = map(int,input().split())
dic_students={}
for i in range(x):
student_num,name,score=input().split()
dic_students.update({student_num:[name,int(score)]})
for j in range(y):
search_num = input()
if dic_students[search_num][1] < 60:
print('ARE YOU PIG?')
else:
print(dic[dic_students[search_num][1]//10])