#AGC062A. [AGC062A] Right Side Character

[AGC062A] Right Side Character

Score : 400400 points

Problem Statement

For a string T=T1T2TnT=T_1T_2\dots T_n of length n (2n)n\ (2\leq n) consisting of A and B, we define a string f(T)f(T) of length n1n-1 as follows.

  • Let a1<a2<<ama_1 < a_2 < \dots < a_{m} be the indices i (1in1)i\ (1\leq i \leq n-1) such that Ti=T_i={}A, and b1<b2<<bkb_1 < b_2 < \dots < b_k be the indices i (1in1)i\ (1\leq i \leq n-1) such that Ti=T_i={}B. Then, let $f(T)=T_{a_1+1}T_{a_2+1}\dots T_{a_m+1}T_{b_1+1}T_{b_2+1}\dots T_{b_k+1}$.

For example, for the string T=T={}ABBABA, the indices i (1i5)i\ (1\leq i \leq 5) with Ti=T_i={}A are i=1,4i=1,4, and the indices i (1i5)i\ (1\leq i \leq 5) with Ti=T_i={}B are i=2,3,5i=2,3,5, so f(T)f(T) is T1+1T4+1T2+1T3+1T5+1=T_{1+1}T_{4+1}T_{2+1}T_{3+1}T_{5+1}={}BBBAA.

You are given a string SS of length NN consisting of A and B.

Find SS after replacing SS with f(S)f(S) (N1)(N-1) times.

You have TT test cases to solve.

Constraints

  • 1T1051 \leq T \leq 10^5
  • 2N3×1052 \leq N \leq 3 \times 10^5
  • SS is a string of length NN consisting of A and B.
  • All numbers in the input are integers.
  • The sum of NN over the test cases in a single input file is at most 3×1053 \times 10^5.

Input

The input is given from Standard Input in the following format:

TT

case1\mathrm{case}_1

\vdots

caseT\mathrm{case}_T

Each case is given in the following format:

NN

SS

Output

Print TT lines. The ii-th line should contain the answer to the ii-th test case.

3
2
AB
3
AAA
4
ABAB
B
A
A

In the first test case, SS changes as AB{}\rightarrow {}B.

In the second test case, SS changes as AAA{} \rightarrow {}AA{} \rightarrow {}A.

In the third test case, SS changes as ABAB{}\rightarrow {}BBA{} \rightarrow {}BA{} \rightarrow {}A.