dic1={10:'A',9:'A',8:'B',7:'C',6:'OK'}
x,y=map(int,input().split())
ls=[]
for i in range(x):
ls.append(input().split())
lsb=[]
for i in range(y):
lsb.append(input())
for j in lsb:
m=j
for i in range(x):
if m==ls[i][0]:
if int(ls[i][2])<60:
print('ARE YOU PIG? ')
else:
t1=int(ls[i][2])//10
print(dic1[t1])
break