Score : $800$ points
Given is a string $S$ consisting of a
and b
. Find the lexicographically greatest string that can be obtained by applying the following operation to $S$ zero or more times:
In this problem, you are given $T$ test cases. The $i$-th test case is represented as $S_i$ and asks you to solve the problem above for $S = S_i$.
a
and b
.Input is given from Standard Input in the following format:
$T$ $S_1$ $\vdots$ $S_T$
Print $T$ lines. The $i$-th line should contain the lexicographically greatest string that can be obtained by applying the operation to $S_i$ zero or more times.
20 abbaa babbb aabbabaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbabaaaaabbaababaaabbabbbbbaaaaa babbbaaaabaababbbabaabaaaaababaa bbaababababbbaaabaabababaabbabab abaabbabaabaaaaabaaaabbaabaaaaab aabababbabbabbabbaaaabbabbbabaab aabababbabbbbaaaabbaaaaabbaaaabb abbbbaabaaabababaaaababababbaabb aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbb aaaaaaaaaabbbbbbbbbbbbbbbbbbbbbb abababaaababaaabbbbbaaaaaaabbbbb aabbaaaaababaabbbbbbbbbaabaaabbb babababbababbbababbbbbababbbabbb bbbbababbababbbabababbabbabbbbbb aaaaaaaaaaaaaaaaababababbbabbbbb aabababbabbabababababababbbbabbb
bba bba bbba aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbaaaaaaaa bbbbbbbbbbbbbaaaaaaa bbbbbbbbbbbbbbbb bbbbbbbbbb bbbbbbbbbbbbbbbbab bbbbbbbbbbbbbb bbbbbbbbbbbbbabb abbbbbbbbb bbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbaaaaaaaaa bbbbbbbbbbbbbbbaaaaa bbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbba bbbbbbbbbaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbba
bba
.bba
.bbabaa
, then do it for the $3$-rd and $5$-th characters to make $S$ bbba
.