n = gets.to_i

n.times do
	
	str = gets.chomp!
    size = (str.size - 4) / 2
    
    stra = ">'"
    strb = ">^"
    
    size.times do
    	stra += '='
        strb += 'Q='
    end
    stra += '#'
    size.times do
    	stra += '='
    end
    stra += "~"
    strb += '~~'
    
    puts stra
    puts strb
    
    if (str == stra)
    	puts "A";
    elsif (str == strb) 
    	puts "B";
    else 
    	puts "NA"
    end
    
end