score = {10:"A",9:"A",8:"B",7:"C",6:"OK",5:"ARE YOU PIG?",
4:"ARE YOU PIG?",3:"ARE YOU PIG?",2:"ARE YOU PIG?",
1:"ARE YOU PIG?",0:"ARE YOU PIG?"}
n,m = map(int,input().split())
d = {}
for tcase in range(n):
a = input().split()
d[a[0]] = int(a[2])
for tcase in range(m):
print(score[d[input()]//10])