n,m=map(int,raw_input().strip().split())
di1={}
di2={}
for i in range(n):
a=raw_input().strip().split()
di1[a[0]]=int(a[2])
di2[a[0]]=a[1]
for j in range(m):
s=di1[raw_input()]
if s>=90:
print "A"
elif s>=80:
print "B"
elif s>=70:
print "C"
elif s>=60:
print "OK"
else:
print "ARE YOU PIG?"