def dengji(s):
if 90<=s<=100:
return "A"
elif s>=80:
return "B"
elif s>=70:
return "C"
elif s>=60:
return "OK"
else: return "ARE YOU PIG?"
x,y=map(int,input().split())
a=[[0 for j in range(3)] for i in range(x)]
for i in range(x):
b=list(input().split())
a[i][0]=int(b[0])
a[i][1]=b[1]
a[i][2]=int(b[2])
for i in range(y):
num=int(input())
for j in a:
if j[0]==num:
print(dengji(j[2]))