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