403286: GYM101102 F Exchange
Description
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”.
InputThe 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.
OutputFor each test case, print the required string on a single line.
ExampleInput3Output
hamza
racecar
mca
ahmzh
arcecra
acm