#P2377. 三角形图
三角形图
Description
UNowen has plane vectors , where:
- ;
- ;
- For any positive integers , there always exists an integer such that ; ()
- Except for the entire vector sequence (same below), there is no contiguous subsequence in the vector sequence whose sum is .
Here denotes “the angle by which is rotated to point in the same direction as ,” where counterclockwise is positive and clockwise is negative (for example, let , , then ).
In other words, all vectors have length , and concatenating them head to tail forms a closed polygon. It is guaranteed that each interior angle of this polygon is an integer multiple of , its interior contains no other vectors, and it is not hollow.
For convenience, we use a string of length over the alphabet to describe .
Specifically, for the -th character in (in particular, is equivalent to , and is equivalent to , similarly below):
| 字符 | 含义 |
|---|---|

In addition, UNowen defines a “standard representation” of a vector sequence as follows:
- For , compute the string corresponding to the vector sequence $\{\bm L_l,\bm L_{l+1},\ldots,\bm L_n,\bm L_1,\bm L_2,\ldots,\bm L_{l-1}\}$.
- Among these strings, take the lexicographically smallest string as the “standard representation” of the vector sequence .
For example, the “standard representation” of the vector sequence in the figure above is , and not .
Now, UNowen gives you the string corresponding to the vector sequence (which is not necessarily its “standard representation”). He hopes you can perform one modification to this vector sequence as follows:
- Choose a positive integer .
- Construct two plane vectors such that:
- ;
- ;
- ;
- .
- Replace with two items (with before ).
- If , delete and .
- If , delete and .
- If after the modification there exists a contiguous subsequence whose sum is (other than the entire vector sequence), then UNowen considers this modification invalid. For example, in the figure below, if you choose , then the modification is invalid.
- UNowen defines the “modification result” as the “standard representation” of the modified vector sequence.
- For any two modification schemes, if the polygons obtained by concatenating the modified vector sequences head to tail are congruent, then UNowen considers the two modification schemes equivalent. For example, in the figure below, the two modification schemes and are equivalent.
- That is, the modification operation constructs an outward equilateral triangle on some vector of the closed polygon, such that the modified shape is still a closed polygon satisfying the above requirements (each interior angle is an integer multiple of , the interior contains no other vectors, and it is not hollow). For any two modification schemes, if the polygons obtained from the modified sequences are congruent, then they are equivalent.

Find the number of pairwise non-equivalent valid modification schemes, and output the “modification result” of each scheme in lexicographic order.
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
The next lines each contain a non-empty string over the alphabet . It is guaranteed that will not appear.
Output Format
For each test case, output three lines:
- The first line contains a positive integer , the number of pairwise non-equivalent valid modification schemes.
- The second line contains non-empty strings over the alphabet (separated by spaces), representing each possible “modification result.” You must output them in lexicographic order. It can be proven that will not appear.
- The third line is an empty line. Please pay special attention to this, as it does not follow the usual data format of traditional problems.
2
eee
cedde
1
dede
3
beddde cdecde cecece
2
adeccecced
dddddd
5
acedccecced addebcecced adebebecced adecbedcced cceccecce
1
cddddce
7
eee
cedde
adeccecced
dddddd
ccdeccde
baedddcdde
abcedcdcddde
1
dede
3
beddde cdecde cecece
5
acedccecced addebcecced adebebecced adecbedcced cceccecce
1
cddddce
4
bcdeccdde bcedccece bdeccdebe cccedccde
8
abdecdcddde abececcddde abedcebddde abeddbecdde abeddccecde abeddcdcece abeddcddced addddcdde
10
abbeddcdcddde abcdeccdcddde abcecebdcddde abcedbeccddde abcedccebddde abcedcdbecdde abcedcdccecde abcedcdcdcece abcedcdcddced acedcdcdddd
Hint
Let be the length of the string .
- For of the testdata, , .
- For of the testdata, it is guaranteed that all modification schemes are valid.
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号