Swap and Explore

All submissions for this problem are available.
Rob likes to explore but is lazy.
He has many cubes arranged before him in a line. Each cube has either the letter 'A' or 'B' inscribed on it.
Now Rob wants to swap any two positions of cubes placed on the line, such that the there exists a sequence of continuous cubes with letter 'A' inscribed on them, whose number is greater than or equal to M.
However, mechanically swapping cubes is a tedious task. Therefore he wishes to know the minimum number of swap operations he has to perform to get such an arrangement of cubes.
Input Format
First line consists of T test cases.
For each test case, first line consists of the string S, composed of A's and B's, representing the initial configuration of cubes, and second line an integer M.
Output Format
The output consists of T lines corresponding to T test cases, such that it is the minimum number of operations required to create a consecutive segment of greater than M A’s from S.
Constraints
 1 ≤ Sum of lengths of S over all test cases ≤ 10^{6}
 1 ≤ Length(S) ≤ 10^{5}
 It is ensured that number of A's are >= M.
Sample Input
1
ABA
2
Sample Output
1
Author:  iopc_admin 
Tags  iopc_admin 
Date Added:  2022014 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP 4.3.2, CPP 4.9.2, GO, JAVA 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
What if number of A's is not
can we swap any two positions
Is M always smaller than the
Can m=0?
@admin I've registered for
@admin could u plz explain
What should be the output in
i dont understand the problem
for swap to occur elements
Many submitted entries have a
Why cant I submit my code???
I did register, still says
What is M please?!