ez
// 5'46"
#include <bits/stdc++.h>
using namespace std;
bool func(int a, int b)
{
int sum = 0;
while(a)
{
sum += a % 10;
a /= 10;
}
return b % sum;
}
signed main()
{
int n;
cin >> n;
for(int i = 1; i <= n; ++ i)
{
int a, b;
cin >> a >> b;
if(func(a, b) && !func(b, a))cout << "A\n";
else if(!func(a, b) && func(b, a)) cout << "B\n";
else cout << (a > b ? "A\n" : "B\n");
}
return 0;
}