x,y=map(int,input().split())
d={}
for i in range(x):
s=list(input().split())
d[s[0]]=int(s[2])
for j in range(y):
score=input()
if d[score]>=90:
print('A')
elif d[score]>=80:
print('B')
elif d[score]>=70:
print('C')
elif d[score]>=60:
print('OK')
else:
print('ARE YOU PIG?')