1
2
3
4
5
6
7
8
9
10
11
12
x,y=map(int,input().split())
level={10:"A",9:"A",8:"B",7:"C",6:"OK"}
a={}
for i in range(x):
s=input().split()
a[s[0]]=[s[1],int(s[2])]
for j in range(y):
cj=a[input()][1]
if cj<60:
print("ARE YOU PIG?")
else:
print(level[cj//10])