Under construction

Still being built. Things may change

ABB to BA (Easy)

Interview

Time limit2sMemory limit1024 MB

Summary
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 tt and nn.

A string SS consisting only of 'A' and 'B' is given. Repeat the following operation until it can no longer be performed.

  • Let ii be the smallest position where the substring "ABB" first appears in SS. Replace the substring "ABB" at that position with "BA".
  • In other words, find the smallest ii such that SiSi+1Si+2S_i S_{i+1} S_{i+2} is "ABB". Replace SiS_i with 'B', replace Si+1S_{i+1} with 'A', and delete Si+2S_{i+2} from SS.
  • If SS does not contain "ABB" as a substring, the operation cannot be performed.

Write a program that prints the contents of SS after the repetitions end.

Input

The first line contains the number of test cases tt. (1≤t≤3001 \le t \le 300)

Each test case consists of two lines.

  • The first line contains the length nn of SS. (1≤n≤2⋅1031 \le n \le 2\cdot 10^3)
  • The second line contains the string SS of length nn. (Every SiS_i is 'A' or 'B')

The sum of nn over all test cases does not exceed 2⋅1032\cdot 10^3.

Output

For each test case, print the contents of SS after the repetitions end, on one line.

Examples1

  1. Example 1

    Input
    3
    3
    ABB
    9
    ABABABBBB
    12
    AAAAAABBBBBB
    
    Expected output
    BA
    BAABA
    AAAABABA