#P1975H. 378QAQ and Core
378QAQ and Core
Description
378QAQ has a string of length . Define the core of a string as the substring with maximum lexicographic order.
For example, the core of "" is "", and the core of "" is "".
378QAQ wants to rearrange the string so that the core is lexicographically minimum. Find the lexicographically minimum possible core over all rearrangements of .
A substring of string is a continuous segment of letters from . For example, "", "" and "" are all substrings of "" while "" and "" are not.
A string is lexicographically smaller than a string if and only if one of the following holds:
- is a prefix of , but ; or
- in the first position where and differ, the string has a smaller element than the corresponding element in (when compared by their ASCII code).
For example, "" and "" are both lexicographically smaller than "" while "" and "" are not.
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the length of string .
The next line of each test case contains the string of length . The string consists of lowercase English letters.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output the lexicographically minimum possible core over all rearrangements of .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the length of string .
The next line of each test case contains the string of length . The string consists of lowercase English letters.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the lexicographically minimum possible core over all rearrangements of .
Note
In the first test case, all possible rearrangements and their corresponding cores are as follows:
- "", its core is "".
- "", its core is "".
- "", its core is "".
So the core with the minimum lexicographic order in all rearrangement plans is "".