AtCoder Regular Contest 179
F
All the Same
AtCoder
⌀ 4037
原题
← E→
翻译中…

Problem Statement

翻译中…

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

翻译中…

For a string $X$ of length $N$ consisting of the characters 1, 2, and 3, the score is determined by the following procedure:

翻译中…

First, initialize the variables $h_1, h_2, h_3, P$ to $0$.

Then, for $i = 1, 2, \dots, N$ in this order, perform the following operations:

  • If the $i$-th character of $S$ is A, perform operation A; if it is B, perform operation B. Let $d$ be the number represented by the $i$-th character of $X$.
  • Operation A: Add $2$ to $h_d$.
    • Operation B: If $d = 2$ or $h_d \neq h_2$, set $P$ to $-10^{100}$. Otherwise, add $1$ to both $h_d$ and $h_2$.
  • If $h_1 = h_2 = h_3$, add $1$ to $P$.

The final value of $P$ is the score.

翻译中…

Print one string $X$ that maximizes the score.

翻译中…

You have $T$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 10^5$
  • $1 \leq N \leq 10^6$
  • $S$ is a string of length $N$ consisting of A and B.
  • $T$ and $N$ are integers.
  • The sum of $N$ across all test cases is at most $10^6$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format. Here, $\mathrm{test}_i$ denotes the $i$-th test case.

翻译中…

T
\mathrm{test}_1
\mathrm{test}_2
\vdots
\mathrm{test}_T

翻译中…

Each test case is given in the following format:

翻译中…

N
S

翻译中…

Output

翻译中…

Print $T$ lines.

翻译中…

The $i$-th line $(1 \leq i \leq T)$ should contain a string $X$ that maximizes the score for the $i$-th test case.

翻译中…

If multiple strings $X$ maximize the score, any of them is considered correct.

翻译中…

样例

Input #1
5
4
ABBA
5
AAAAA
6
BBBBBB
7
ABABABA
20
AAABBBBBBBBAAABBBABA
Output #1
1333
12321
333333
1313212
33311111133121111311
Let us describe the changes in $(h_1, h_2, h_3, P)$ as we proceed with $i = 1, 2, \dots, N$. - For the first test case, $(0,0,0,0) \rightarrow (2,0,0,0) \rightarrow (2,1,1,0) \rightarrow (2,2,2,1) \rightarrow (2,2,4,1)$. The maximum score is $1$. - For the second test case, $(0,0,0,0) \rightarrow (2,0,0,0) \rightarrow (2,2,0,0) \rightarrow (2,2,2,1) \rightarrow (2,4,2,1) \rightarrow (4,4,2,1)$. The maximum score is $1$. For the third, fourth, and fifth test cases, the maximum scores are $0$, $0$, and $2$, respectively. There may be multiple strings $X$ that maximize the score, but you only need to print one of them.
题目信息
题号
arc179_f
时间限制
2 s
内存限制
1024 MB

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