#include<iostream>
#include<string>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
	int n;

		for(int x=0;x<n;++x){
			string line;
			cin>>line;
			string sol = "NA";
			if(line.find('#')!=string::npos){
				bool flag = false;
				string a = "";
				string b = "";
				for(int x=2;x<line.size()-1;++x){
					if(line[x] == '#'){
						flag = true;
						continue;
					}
					if(!flag){
						a += line[x];
					}else{
						b += line[x];
					}
				}
				if(line.size()> 3 && line[0]=='>' && line[1]=='\'' && line[line.size()-1]=='~' && a==b)sol = "A";
			}else{
				bool flag = true;
				for(int x=2;line.size()>4 && x<(line.size()-3);x+=2){
				
					//cout<<"OK"<<endl;
					if(line[x] !='Q' || line[x+1] != '=')flag = false;
				}
				if(line.size()>4 && line[0]=='>' && line[1]=='^' && line[line.size()-1]=='~' && line[line.size()-2]=='~' && flag)sol = "B";
			}
			cout<<sol<<endl;
		}
	
	return 0;
}