#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int get(int a)
{
int res = 0;
while (a) res += a % 10, a /= 10;
return res;
}
int main()
{
int n;
cin >> n;
while (n -- )
{
int a, b, sa, sb;
cin >> a >> b;
sa = get(a), sb = get(b);
bool fa = !(a % sb), fb = !(b % sa);
if (fa ^ fb) cout << "AB"[fb] << endl;
else cout << "AB"[b > a] << endl;
}
return 0;
}