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