m=list(map(int,(input().split())))
d={}
for i in range(m[0]):
a = input().split()
a[2] = int(a[2])
d[a[0]]=a[2]
for j in range(m[1]):
b=input()
if d[b]<=100 and d[b]>=90:
print("A")
if d[b]<90 and d[b]>=80:
print("B")
if d[b]<80 and d[b]>=70:
print("C")
if d[b]<70 and d[b]>=60:
print("OK")
if d[b]<60:
print("ARE YOU PIG?")