ABB to BA (Easy)
InterviewTime limit2sMemory limit1024 MB
Repeatedly replace the leftmost "ABB" with "BA" in a string of A and B characters, then print the final string.
- Level
Medium4 of 10
- Topics
- String, Simulation
- Solved
- No attempts yet
Problem
This is the easy version of "ABB to BA". The two versions are identical except for the limits on and .
A string consisting only of 'A' and 'B' is given. Repeat the following operation until it can no longer be performed.
- Let be the smallest position where the substring
"ABB"first appears in . Replace the substring"ABB"at that position with"BA". - In other words, find the smallest such that is
"ABB". Replace with'B', replace with'A', and delete from . - If does not contain
"ABB"as a substring, the operation cannot be performed.
Write a program that prints the contents of after the repetitions end.
Input
The first line contains the number of test cases . ()
Each test case consists of two lines.
- The first line contains the length of . ()
- The second line contains the string of length . (Every is
'A'or'B')
The sum of over all test cases does not exceed .
Output
For each test case, print the contents of after the repetitions end, on one line.