import logging
ls01=[]
x,y=list(map(int,(input().split())))
for i in range(x):
ls001=input().split()
ls001[0]=int(ls001[0])
ls001[2]=int(ls001[2])
ls01.append(ls001)
for i in range(y):
a=int(input())
##ls01=[[1000001,"szy",100],
## [1000002,"wxa",98],
## [1000003,"zz",95],
## [1000004,"yl",80],
## [1000005,"loy", 59]]
##a=1000003
for i in ls01:
if i[0]==a:
s=i[2]
if s>=90 and s<=100:
print("A")
if s>=80 and s<90:
print("B")
if s>=70 and s<80:
print("C")
if s>=60 and s<70:
print("OK")
if s<60:
print("ARE YOU PIG?")