AtCoder Grand Contest 062
A
Right Side Character
AtCoder
⌀ 1099
原题
←B →
翻译中…

Problem Statement

翻译中…

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

翻译中…
  • Let $a_1 < a_2 < \dots < a_{m}$ be the indices $i\ (1\leq i \leq n-1)$ such that $T_i={}$A, and $b_1 < b_2 < \dots < b_k$ be the indices $i\ (1\leq i \leq n-1)$ such that $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={}$ABBABA, the indices $i\ (1\leq i \leq 5)$ with $T_i={}$A are $i=1,4$, and the indices $i\ (1\leq i \leq 5)$ with $T_i={}$B are $i=2,3,5$, so $f(T)$ is $T_{1+1}T_{4+1}T_{2+1}T_{3+1}T_{5+1}={}$BBBAA.

翻译中…

You are given a string $S$ of length $N$ consisting of A and B.

翻译中…

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

翻译中…

You have $T$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 10^5$
  • $2 \leq N \leq 3 \times 10^5$
  • $S$ is a string of length $N$ consisting of A and B.
  • All numbers in the input are integers.
  • The sum of $N$ over the test cases in a single input file is at most $3 \times 10^5$.
翻译中…

Input

翻译中…

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

翻译中…

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

翻译中…

Each case is given in the following format:

翻译中…

N
S

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain the answer to the $i$-th test case.

翻译中…

样例

Input #1
3
2
AB
3
AAA
4
ABAB
Output #1
B
A
A
In the first test case, $S$ changes as `AB`${}\rightarrow {}$`B`. In the second test case, $S$ changes as `AAA`${} \rightarrow {}$`AA`${} \rightarrow {}$`A`. In the third test case, $S$ changes as `ABAB`${}\rightarrow {}$`BBA`${} \rightarrow {}$`BA`${} \rightarrow {}$`A`.
题目信息
题号
agc062_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。