for r in range(eval(input())):

	snake=input()

	L=len(snake)

	if L>5 and snake == ">'" + "="*((L-4)/2) + "#" + "="*((L-4)/2) + "~":

		print("A")

	elif L>5 and snake == ">^" + "Q="*((L-4)/2) + "~~":

		print("B")

	else:

		print("NA")
for r in range(eval(input())):

	snake=input()

	m=(len(snake)-4)/2

	if m>0 and snake == ">'" + "="*m + "#" + "="*m + "~":

		print("A")

	elif m>0 and snake == ">^" + "Q="*m + "~~":

		print("B")

	else:

		print("NA")
for r in range(eval(input())):
    snake = input()
    L = len(snake)
    if L > 5 and snake == ">'" + "=" * ((L - 4) / 2) + "#" + "=" * ((L - 4) / 2) + "~":
        print("A")
    elif L > 5 and snake == ">^" + "Q=" * ((L - 4) / 2) + "~~":
        print("B")
    else:
        print("NA")

for r in range(eval(input())):
    snake = input()
    m = (len(snake) - 4) / 2
    if m > 0 and snake == ">'" + "=" * m + "#" + "=" * m + "~":
        print("A")
    elif m > 0 and snake == ">^" + "Q=" * m + "~~":
        print("B")
    else:
        print("NA")

-    L = len(snake) -    if L > 5 and snake == ">'" + "=" * ((L - 4) / 2) + "#" + "=" * ((L - 4) / 2) + "~": +    m = (len(snake) - 4) / 2 +    if m > 0 and snake == ">'" + "=" * m + "#" + "=" * m + "~": -    elif L > 5 and snake == ">^" + "Q=" * ((L - 4) / 2) + "~~": +    elif m > 0 and snake == ">^" + "Q=" * m + "~~":