Hide

Problem C
Match Results

Alice and Bob decided to play a series of matches, where each match consisted of a series of games. The winner of each match was the first player to win exactly $k$ games, at which point the match ended. You are given the result of all $n$ games they played (across all matches), in order. What are all possible values of $k$?

This diagram shows an example for $n=15$, $k=4$:

\includegraphics{matches.png}

However, $k=3$ would not work in this case, because it would end with an incomplete match:

\includegraphics{matches2.png}

Input

The first line of the input contains a single integer $t$ ($1 \le t \le 10^4$) —the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^6$) —the total number of games played by Alice and Bob.

The second line of each test case contains a string $s$ containing $n$ characters —the results of the $n$ games. The $i$-th character of $s$ is $A$ if Alice won the $i$-th game, and $B$ otherwise.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output

The first line of output for each test case should contain a single integer $m$ —the number of possible values of $k$.

The second line of output for each test case should contain $m$ distinct integers in ascending order —the possible values of $k$.

Sample Input 1 Sample Output 1
7
1
B
3
BAB
5
ABBAA
6
AAAAAA
7
BBAABBA
8
AAAAABBB
15
ABAAABBBBBBAABB
1
1
2
1 2
3
1 2 3
4
1 2 3 6
1
1
2
1 3
4
1 2 4 9

Please log in to submit a solution to this problem

Log in