x,y=map(int,raw_input().strip().split())
dic={}
for i in range(x):
z=raw_input().strip().split()
dic[z[0]]=int(z[2])
for i in range(y):
a=dic[raw_input()]
if a>=90 and a<=100:
print 'A'
elif a>=80:
print 'B'
elif a>=70:
print 'C'
elif a>=60:
print 'OK'
else:
print 'ARE YOU PIG?'