#P16968. [SCCPC 2026] 博德之跃 3
[SCCPC 2026] 博德之跃 3
Problem Description
You are given a string consisting of lowercase English letters, and an initially empty string .
You need to perform some operations on until it becomes an empty string. Each time, you may perform one of the following three operations:
- Delete the first character of and append it to the end of .
- Delete the last character of and append it to the end of .
- Choose non-empty strings such that . Let , and append the string to the end of .
Here, denotes the reverse of the string .
Among all possible sequences of operations, find the lexicographically smallest that can be obtained.
Input Format
This problem contains multiple testdata.
The first line contains a positive integer (), denoting the number of test cases.
For each test case:
Input one line containing a string of lowercase letters ().
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output one line containing a string representing the answer.
6
cba
zayaz
aaaaa
xazbx
ababa
aa
abc
zaay
aaa
xabz
aaba
aa
Hint
Translated by ChatGPT 5