def pd(x):
if x>=90 and x<=100:
return "A"
elif x>=80 and x<90:
return "B"
elif x>=70 and x<80:
return "C"
elif x>=60 and x<70:
return "OK"
else:
return "ARE YOU PIG?"
x,y=map(int,input().split())
s1,s2=[],[]
for i in range(x):
s2.append(list(input().split()))
for j in range(y):
s1.append(input())
for p in s1:
for j in s2:
if p in j:
print(pd(int(j[2])))