string t= abacaba the upsides of the prefix work in positions 1,2,… ,7 are equivalent to [0,0,1,0,1,2,3]. Let f(t) be equivalent to the greatest worth of the prefix capacity of string t over the entirety of its positions. For instance, f(abacaba)=3.
Correct answer will be upvoted else downvoted.
for string t= abacaba the upsides of the prefix work in positions 1,2,… ,7 are equivalent to [0,0,1,0,1,2,3].
Let f(t) be equivalent to the greatest worth of the prefix capacity of string t over the entirety of its positions. For instance, f(abacaba)=3.
You are given a string s. Reorder its characters self-assertively to get a string t (the number of events of any character in strings s and t should be equivalent). The worth of f(t) should be limited. Out of all choices to limit f(t), pick the one where string t is the lexicographically littlest.
Input
Each test contains various experiments. The principal line contains the number of experiments t (1≤t≤105). Portrayal of the experiments follows.
The main line of each experiment contains string s (1≤|s|≤105) comprising of lowercase English letters.
It is ensured that the amount of lengths of s over all experiments doesn't surpass 105.
Output
For each experiment print a solitary string t.
The multisets of letters in strings s and t should be equivalent. The worth of f(t), the limit of prefix capacities in string t, should be pretty much as little as could be expected. String t should be the lexicographically littlest string out of all strings fulfilling the past conditions.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)