#include using namespace std; void validate(string s) { int n = (int)s.size(); assert(n >= 1 && n <= 500); for ( int i = 0; i < n; i++ ) { assert(s[i] >= 'a' && s[i] <= 'z'); } } int cnt_s[26]; int cnt_t[26]; int main() { int tc, n; string s, t; bool flag; cin >> tc; assert(tc >= 1 && tc <= 500); while ( tc-- ) { cin >> s >> t; validate(s); validate(t); assert(s.size() == t.size()); memset(cnt_s, 0, sizeof(cnt_s)); memset(cnt_t, 0, sizeof(cnt_t)); n = (int)s.size(); for ( int i = 0; i < s.size(); i++ ) { cnt_s[s[i] - 'a']++; cnt_t[t[i] - 'a']++; } flag = false; for ( int i = 0; i < 26; i++ ) { if ( cnt_s[i] > 1 && cnt_t[i] == 0 ) { flag = true; break; } } if ( flag ) { puts("A"); continue; } bool f1 = false, f2 = false; for ( int i = 0; i < 26; i++ ) { if ( cnt_s[i] > 0 && cnt_t[i] == 0 ) f1 = true; if ( cnt_t[i] > 0 && cnt_s[i] == 0 ) f2 = true; } if ( !f2 && f1 ) { puts("A"); continue; } puts("B"); } return 0; }