x,y=map(int,input().split())
score_dict={}
for xx in range(x):
n,m,s=input().split()
score_dict[n]=int(s)
for yy in range(y):
roll=input()
score=score_dict[roll]
if score>=90:
print('A')
elif score>=80:
print('B')
elif score>=70:
print('C')
elif score>=60:
print('OK')
else:
print('ARE YOU PIG?')