You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string *s* of length between 1 and 10<sup class="upper-index">5</sup> consisting of uppercase Latin letters.
import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline


for _ in range(int(input())):
    a = input()
    ab=0
    ba=0
    ov=0
    for x in range(len(a)):
        if a[x]=='A':
            try:
                if a[x+1]=='B':
                    ab+=1
                    try:
                        if a[x+2]=='A':
                            ov+=1
                    except:
                        pass
            except :
                pass
    ab-=ov
    ov=0
    for x in range(len(a)):
        if a[x]=='B':
            try:
                if a[x+1]=='A':
                    ba+=1
                    try:
                        if a[x+2]=='B':
                            ov+=1
                    except:
                        pass
            except :
                pass

    ba-=ov
    if ba>0 and ab>0:
        print('YES')
    else:
        print('NO')





            

    




