← Home
write a go solution for Description:
Miriany's matchstick is a 2xn grid that needs to be filled with characters A or B.

He has already filled in the first row of the grid and would like you to fill in the second row. You must do so in a way such that the number of adjacent pairs of cells with different characters^dagger is equal to k. If it is impossible, report so.

^dagger An adjacent pair of cells with different characters is a pair of cells (r_1,c_1) and (r_2,c_2) (1<=r_1,r_2<=2, 1<=c_1,c_2<=n) such that |r_1-r_2|+|c_1-c_2|=1 and the characters in (r_1,c_1) and (r_2,c_2) are different.

Input Format:
The first line consists of an integer t, the number of test cases (1<=t<=1000). The description of the test cases follows.

The first line of each test case has two integers, n and k (1<=n<=2*10^5,0<=k<=3*n) – the number of columns of the matchstick, and the number of adjacent pairs of cells with different characters required.

The following line contains string s of n characters (s_i is either A or B) – Miriany's top row of the matchstick.

It is guaranteed that the sum of n over all test cases does not exceed 2*10^5.

Output Format:
For each test case, if there is no way to fill the second row with the number of adjacent pairs of cells with different characters equals k, output "NO".

Otherwise, output "YES". Then, print n characters that a valid bottom row for Miriany's matchstick consists of. If there are several answers, output any of them.

Note:
In the first test case, it can be proved that there exists no possible way to fill in row 2 of the grid such that k=1.

For the second test case, BABB is one possible answer.

The grid below is the result of filling in BABB as the second row.

beginarray|c|c|hlineA&A&A&AcrhlineB&A&B&Bcrhlineendarray

The pairs of different characters are shown below in red:

beginarray|c|c|hlinecolorredA&A&A&AcrhlinecolorredB&A&B&Bcrhlineendarray—————————————————beginarray|c|c|hlineA&A&colorredA&AcrhlineB&A&colorredB&Bcrhlineendarray—————————————————beginarray|c|c|hlineA&A&A&colorredAcrhlineB&A&B&colorredBcrhlineendarray—————————————————beginarray|c|c|hlineA&A&A&AcrhlinecolorredB&colorredA&B&Bcrhlineendarray—————————————————beginarray|c|c|hlineA&A&A&AcrhlineB&colorredA&colorredB&Bcrhlineendarray

There are a total of 5 pairs, which satisfies k.. Output only the code with no comments, explanation, or additional text.