n, m = map(int,input().split())
a = []
for i in range(n):
s = input().split()
a.append([s[0], int(s[2])])
for i in range(m):
h = input()
for j in range(n):
if h == a[j][0]:
s = a[j][1]
break;
if s>=90: print("A")
elif s>=80: print("B")
elif s>=70: print("C")
elif s>=60: print("OK")
else: print("ARE YOU PIG?")