AT_agc076_b [AGC076B] Split and Reverse
Description
You are given an integer sequence $ X=(X_1,X_2,\cdots,X_N) $ of length $ N $ consisting of $ 0 $ and $ 1 $ .
You can perform the following operation zero or more times:
- Classify each element of $ X $ into group `A` or group `B`. Then, for each group, reverse the order of the elements it contains. More formally, if the elements contained in a group are $ X_{i_1},X_{i_2},\cdots,X_{i_s} $ ( $ i_1
Input Format
The input is given from Standard Input in the following format:
> $ T $ $ case_1 $ $ case_2 $ $ \vdots $ $ case_T $
Each test case is given in the following format:
> $ N $ $ X_1 $ $ X_2 $ $ \cdots $ $ X_N $
Output Format
For each case, output in the following format:
> $ k $ $ s_1 $ $ s_2 $ $ \vdots $ $ s_k $
Here, $ k $ is the minimum number of operations needed, and $ s_i $ is a string representing the $ i $ -th operation. $ s_i $ is a string of length $ N $ consisting of `A` and `B`, and the $ j $ -th character of $ s_i $ represents the group to which $ X_j $ is assigned in the $ i $ -th operation. If there are multiple solutions, you may output any of them.
Explanation/Hint
### Sample Explanation 1
For the first test case, the goal can be achieved in two operations as follows, which is the minimum number of operations:
- First operation: Use $ s_1 $ =`AABA`. Since $ (X_1,X_2,X_4) $ are in group `A`, reverse their order, resulting in $ (X_1,X_2,X_4)=(1,1,0) $ . Similarly, since $ (X_3) $ is in group `B`, reverse their order, resulting in $ (X_3)=(0) $ . Thus, overall we get $ X=(1,1,0,0) $ .
- Second operation: Use $ s_2 $ =`BBBB`. Since $ () $ are in group `A`, reverse their order, resulting in $ ()=() $ . Similarly, since $ (X_1,X_2,X_3,X_4) $ are in group `B`, reverse their order, resulting in $ (X_1,X_2,X_3,X_4)=(0,0,1,1) $ . Thus, overall we get $ X=(0,0,1,1) $ .
For the second test case, the goal can be achieved by performing the operation zero times.
### Constraints
- $ 1 \leq T \leq 250000 $
- $ 1 \leq N \leq 250000 $
- $ 0 \leq X_i \leq 1 $
- The sum of $ N $ over the $ T $ cases is at most $ 250000 $ .
- All input values are integers.