Codeforces Round 968 (Div. 2)
C
Turtle and Good Pairs
Codeforces
1200
原题
← BD1 →
翻译中…

Turtle gives you a string $s$, consisting of lowercase Latin letters.

翻译中…

Turtle considers a pair of integers $(i, j)$ ($1 \le i \lt j \le n$) to be a pleasant pair if and only if there exists an integer $k$ such that $i \le k \lt j$ and both of the following two conditions hold:

翻译中…
  • $s_k \ne s_{k + 1}$;
  • $s_k \ne s_i$ or $s_{k + 1} \ne s_j$.
翻译中…

Besides, Turtle considers a pair of integers $(i, j)$ ($1 \le i \lt j \le n$) to be a good pair if and only if $s_i = s_j$ or $(i, j)$ is a pleasant pair.

翻译中…

Turtle wants to reorder the string $s$ so that the number of good pairs is maximized. Please help him!

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the string.

翻译中…

The second line of each test case contains a string $s$ of length $n$, consisting of lowercase Latin letters.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output the string $s$ after reordering so that the number of good pairs is maximized. If there are multiple answers, print any of them.

翻译中…

Note

翻译中…

In the first test case, $(1, 3)$ is a good pair in the reordered string. It can be seen that we can't reorder the string so that the number of good pairs is greater than $1$. bac and cab can also be the answer.

翻译中…

In the second test case, $(1, 2)$, $(1, 4)$, $(1, 5)$, $(2, 4)$, $(2, 5)$, $(3, 5)$ are good pairs in the reordered string. efddd can also be the answer.

翻译中…

样例

Input #1
5
3
abc
5
edddf
6
turtle
8
pppppppp
10
codeforces
Output #1
acb
ddedf
urtlet
pppppppp
codeforces
InputCopy OutputCopy
题目信息
题号
2003C
时间限制
2 s
内存限制
256 MB
标签
构造
贪心
排序
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。