#include<iostream>
#include<string>
using namespace std;

int main(void){
  string str;
  int n;
  cin>>n;
  while(n--){
    cin>>str;
    int ca = 0;
    int cntsha = 0;
    bool a = true;
    if(str.size()%2 == 0){
      if(str[str.size() / 2] == '#')str[str.size()/2] = '=';
      for(int i = 2 ; i < str.size() - 1 ; i ++){
	if(str[i] != '='){
	  a = false;
	  break;
	}
      } 
      if(a)ca = 1;
    }
    if(ca != 1){
    bool b = true;
    for(int i = 2 ; i < str.size() - 2 ; i ++){
      //cout<<str[i];
      if(i%2){
	if(str[i] != '='){
	  b = false;
	  //cout<<i<<endl;
	  break;
	}
      }else{
	if(str[i] != 'Q'){
	  b = false;
	  //cout<<i<<endl;
	  break;
	}	
      }
    }
    if(b){
      ca = 2;
    }
    }
    if(ca == 1){
      cout<<"A"<<endl;
    }else if(ca == 2){
      cout<<"B"<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
}
#include<iostream>
#include<string>
using namespace std;

int main(void){
  string str;
  int n;
  cin>>n;
  while(n--){
    cin>>str;
    int ca = 0;
    int cntsha = 0;
    bool a = true;
    if(str.size()%2 == 0){
      if(str[str.size() / 2] == '#')str[str.size()/2] = '=';
      for(int i = 2 ; i < str.size() - 1 ; i ++){
	if(str[i] != '='){
	  a = false;
	  break;
	}
      } 
      if(a)ca = 1;
    }
    if(ca != 1){
    bool b = true;
    for(int i = 2 ; i < str.size() - 2 ; i ++){
      //cout<<str[i];
      if(i%2){
	if(str[i] != '='){
	  b = false;
	  //cout<<i<<endl;
	  break;
	}
      }else{
	if(str[i] != 'Q'){
	  b = false;
	  //cout<<i<<endl;
	  break;
	}	
      }
    }
    if(b){
      ca = 2;
    }
    }
    if(ca == 1){
      cout<<"A"<<endl;
    }else if(ca == 2){
      cout<<"B"<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
}