#agc062a. [agc062_a]Right Side Character

[agc062_a]Right Side Character

Problem Statement

For a string T=T1T2dotsTnT=T_1T_2\\dots T_n of length n(2leqn)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<dots<ama_1 < a_2 < \\dots < a_{m} be the indices i(1leqileqn1)i\\ (1\\leq i \\leq n-1) such that Ti=T_i={}A, and b1<b2<dots<bkb_1 < b_2 < \\dots < b_k be the indices i(1leqileqn1)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(1leqileq5)i\\ (1\\leq i \\leq 5) with Ti=T_i={}A are i=1,4i=1,4, and the indices i(1leqileq5)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

  • 1leqTleq1051 \\leq T \\leq 10^5
  • 2leqNleq3times1052 \\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 3times1053 \\times 10^5.

Input

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

TT mathrmcase1\\mathrm{case}_1 vdots\\vdots mathrmcaseT\\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.


Sample Input 1

3
2
AB
3
AAA
4
ABAB

Sample Output 1

B
A
A

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

In the second test case, SS changes as AAArightarrow{} \\rightarrow {}AArightarrow{} \\rightarrow {}A.

In the third test case, SS changes as ABABrightarrow{}\\rightarrow {}BBArightarrow{} \\rightarrow {}BArightarrow{} \\rightarrow {}A.