You are given a string
, consisting of lowercase English letters. You can do the following operation at most once :
- Choose a subsequence of the string , then remove it from and concatenate the subsequence at the end of the remaining string.
Find the lexicographically minimum string that can be obtained by performing this operation at most once on .
Note that:
- A string is a subsequence of a string if can be obtained by deleting several (possibly, zero or all) characters from .
- Given two strings of the same length and , we say that is lexicographically smaller than if there exists an index such that and .
Input Format
- The first line of input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains a string .
Output Format
For each test case, print a single line containing the lexicographically minimum string which can be obtained from by performing the given operation at most once.
Constraints
- contains only lowercase English letters.
- Sum of over all test cases does not exceed .
Subtasks
- Subtask 1 (100 points): Original constraints
Sample Input 1
4
aba
abcd
cbcdbef
fabcdac
Sample Output 1
aab
abcd
bbccdef
aacfbcd
Explanation
Test case : It is optimal to choose the subsequence , then remove and concatenate the subsequence at the end of the remaining string . Hence the final string is .
Test case : The given string is already lexicographically minimum.
Test case : It is optimal to choose the subsequence , then remove and concatenate the subsequence at the end of the remaining string . Hence the final string is .
ConversionConversion EmoticonEmoticon