x,y = map(int,input().split())
dic = {}
for i in range(x):
n,m,s = input().split()
dic[n] = [m,int(s)]
for i in range(y):
a = input()
score = dic[a][1]
if 90<=score<=100:
print("A")
elif 80<=score<90:
print("B")
elif 70<=score<80:
print("C")
elif 60<=score<70:
print("OK")
elif score<60:
print("ARE YOU PIG?")