for i in [0]*eval(input()):

  s=input()

  n=(len(s)-4)/2

  if s==">'"+"="*n+"#"+"="*n+"~": t="A"

  elif s==">^"+"Q="*n+"~~": t="B"

  else: t="NA"

  if n<1: t="NA"

  print(t)
for i in [0]*eval(input()):

  s=input()

  n=(len(s)-4)/2

  if n>0 and s==">'"+"="*n+"#"+"="*n+"~": t="A"

  elif n>0 and s==">^"+"Q="*n+"~~": t="B"

  else: t="NA"

  print(t)
for i in [0] * eval(input()):
    s = input()
    n = (len(s) - 4) / 2
    if s == ">'" + "=" * n + "#" + "=" * n + "~":
        t = "A"
    elif s == ">^" + "Q=" * n + "~~":
        t = "B"
    else:
        t = "NA"
    if n < 1:
        t = "NA"
    print(t)

for i in [0] * eval(input()):
    s = input()
    n = (len(s) - 4) / 2
    if n > 0 and s == ">'" + "=" * n + "#" + "=" * n + "~":
        t = "A"
    elif n > 0 and s == ">^" + "Q=" * n + "~~":
        t = "B"
    else:
        t = "NA"
    print(t)

-    if s == ">'" + "=" * n + "#" + "=" * n + "~": +    if n > 0 and s == ">'" + "=" * n + "#" + "=" * n + "~": -    elif s == ">^" + "Q=" * n + "~~": +    elif n > 0 and s == ">^" + "Q=" * n + "~~": -    if n < 1: -        t = "NA"