n,m=map(int,input().split())
d={}
for tcase in range(n):
a=input().split()
d[a[0]]=int(a[2])
for tcase in range(m):
x=d[input()]
if 90<=x<=100:
print('A')
elif 80<=x<=90:
print('B')
elif 70<=x<=80:
print('C')
elif 60<=x<=70:
print('OK')
else:
print('ARE YOU PIG?')