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