Given a string of lowercase English letters. You are allowed to choose two letters that exist in any position in the string, replace all occurrences of the first letter you chose with the second one, and replace all occurrences of the second letter you chose with the first one.
Your task is to find the string that comes first in dictionary order among all possible strings that you can get by performing the above operation at most once.
For example, by exchanging letter ‘a’ with letter ‘h’ in string “hamza”, we can get string “ahmzh”.
Input
The first line of input contains a single integer T, the number of test cases.
Each test case contains a non-empty string on a single line that contains no more than 105 lowercase English letters.
Output
For each test case, print the required string on a single line.
Example
Input
3
hamza
racecar
mca
Output
ahmzh
arcecra
acm
题意:可以对字符串进行一个操作,把2个字母互换(这2个字母是不同的),一旦互换必须把所有x换成y,所有y换成x,最多可以进行一次这样的操作,求字典序最小的字符串。
以s1[i]记录第i个字符是否可以用来交换,以s2[i]记录第i个字符是否在之前已经出现过,对于第i个字符,如果s2[i]=1说明之前已经出现过这个字符,之前就没换现在肯定也不会换,如果s2[i]=0说明这个字符可能可以换,那么就找最小的j满足s1[j]=1表示第i个字符能够用来交换,那么交换s[i]和j+’a’即可