You are given a string S of N characters comprising of A′s and B′s. You can choose any index i and change Si to either A or B.
Find the minimum number of changes that you must make to string S such that the resulting string is of the following format:
AAAA........⏟x number of A′sBBBB........⏟n−x number of B′s
where 0≤x≤n
In other words, your task is to determine the minimum number of changes such that string S has x number of A′s in the beginning, followed by the remaining (n−x) number of B′s.
Input format
Output format
For each test case, print a single line containing one integer that represents the minimum number of changes you need to make in string S as mentioned in the question.
Constraints
1≤T≤1041≤N≤106
Note: Sum of N overall test cases does not exceed 5×106
For the string AAB we don't need to make any changes.
For the string AABAA we can change B to A and get the string in the required form.
For the string B we don't need to make any changes.
For the string BABA we need to make atleast 2 changes to get the string in required form. One possible way is AABB