#C8924. Lexicographically Smallest String after Reversal
Lexicographically Smallest String after Reversal
Lexicographically Smallest String after Reversal
Given a string \(s\), you are required to reverse exactly one contiguous substring (which could be as small as a single character) such that the resulting string is the lexicographically smallest possible.
More formally, for a given string \(s\) of length \(n\), you need to choose two indices \(i\) and \(j\) (with \(1 \leq i \leq j \leq n\)) and reverse the substring \(s[i\ldots j]\). Let \(s'\) be the resulting string after this reversal. Your task is to find the smallest string \(s'\) possible in lexicographic order.
Note: Even if the string is already in the smallest possible order, you must perform a reversal (for example, reversing a single character does not change the string).
inputFormat
The input is given from standard input. The first line contains an integer \(T\) \( (T \geq 1)\) representing the number of test cases. Each of the following \(T\) lines contains a non-empty string \(s\) consisting of lowercase English letters.
Constraints: \(1 \leq |s| \leq 100\) (for the purpose of this problem, the input sizes are kept small enough to allow a brute force solution).
outputFormat
For each test case, output the lexicographically smallest string obtainable by reversing exactly one substring of the input string. Each result should be printed on a separate line to standard output.
## sample5
cba
geek
abcd
zyx
gfedcba
abc
eegk
abcd
xyz
abcdefg
</p>