x,y=map(int,input().split())
dic={}
dic2={10:"A",9:"A",8:"B",7:"C",6:"OK"}
for i in range(x):
nu,na,sc=input().split()
dic[nu]=[na,int(sc)]
for j in range(y):
s_nu=input()
t_sc=dic[s_nu][1]
if t_sc//10<6:
print("ARE YOU PIG?")
else:
print(dic2[t_sc//10])