In the while version, you haven’t decremented t in the case of no score. The continue restarts the next pass of the loop without executing that. That means that you lose track of the number of test cases performed and try to pull output after the last test case, which gives you your error.
Arguably you could decrement t immediately (at the top of the while loop), but the for statement in this case seems better.
for _ in range(int(input())):
vs = input().strip()
ctA = sum(len(Ai.strip('.')) for Ai in vs.split('B'))
ctB = sum(len(Bi.strip('.')) for Bi in vs.split('A'))
print(ctA, ctB)
Note, this is not a “correction” - your general approach is good - it’s just intended for interest, with an element of challenge to figure out how it works .