x,y=map(int,input().split())
a=[]
for i in range(x):
a.append(input().split())
y=int(y)
while y:
b=input()
for i in range(x):
if a[i][0]==b:
c=int(a[i][2])
break
if c>=90 and c<=100:
print("A")
elif c>=80 and c<90:
print("B")
elif c>=70 and c<80:
print("C")
elif c>=60 and c<70:
print("OK")
else:
print("ARE YOU PIG?")
y=y-1