#include <bits/stdc++.h>
using namespace std;
long int a,b,suma,sumb;
char ma;
int main(){
int n;
cin>>n;
while(n--){
cin>>a>>b;
long int a1=a,b1=b;
if(a>b) ma='A'; else ma='B';
long c=a,d=b;
while(a){
suma+=a%10;
a=a/10;
}
while(b){
sumb+=b%10;
b=b/10;
}
a=a1,b=b1;
if(a%sumb==0&&b%suma!=0) cout<<"A"<<endl;
else if(a%sumb!=0&&b%suma==0) cout<<"B"<<endl;
else cout<<ma<<endl;
suma=0,sumb=0;
}
return 0;
}