| OCPC 2025 Summer, Day 2: KIT Contest |
|---|
| Finished |
After building wells last year, Bob is back to building walls, just as he did two years ago. To help mitigate his boredom from doing the same task again, he is allowed to destroy some part of his own creation. The project he is working on right now is building a wall for a playground with letters written on it.
During the construction, the assembly line feeds him one building block at a time, each with one letter written on the block. He can decide whether to use this block to extend the current wall to the right, or if there is at least one intact block, he can smash the new block into the rightmost existing wall block, destroying both in the process.
Bob knows that the children frequenting the playground are most impressed by large objects, so he wants to create the largest possible writing on the wall; that is, the string formed by the letters of the intact building blocks from left to right should be lexicographically maximal. What is this maximum string Bob can build?
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$), the number of testcases.
Each testcase consists of:
The strings contain only upper case letters, and the sum of $$$|s|$$$ over all testcases is at most $$$10^6$$$.
For each testcase, output one string – the lexicographically largest string Bob can build.
5EDCBAABBAXYZBABAZZAAAAAAAAA
EDCBA BA Z ZZ AAAAAAAAA
In the third testcase, Bob uses the first block to build the wall "X", then smashes the 'Y' block into the wall, leaving behind an empty wall. Finally, he uses the 'Z' block to finish with the wall "Z".
| Name |
|---|


