AtCoder Regular Contest 209 (Div. 1)
B
Minimize Even Palindrome
AtCoder
⌀ 1787
原题
← AC →
翻译中…

Problem Statement

翻译中…

For a string $s$ consisting of lowercase English letters, let $f(s)$ denote the number of substrings of $s$ that are palindromes of even length. More precisely, $f(s)$ is the number of pairs of integers $l, r$ that satisfy all of the following conditions:

翻译中…
  • $1 \leq l \leq r \leq |s|$.
  • $r - l + 1$ is even.
  • $s_l s_{l+1} \cdots s_{r}$ is a palindrome.
翻译中…

Given a string $S$ consisting of lowercase English letters, output one string $S'$ obtained by rearranging the characters of $S$ such that $f(S')$ is minimized.

翻译中…

You are given $T$ test cases. Solve each of them.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 10^5$
  • $2 \le |S| \le 2 \times 10^5$
  • $S$ consists of lowercase English letters.
  • The sum of $|S|$ over all test cases is at most $2 \times 10^5$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

S

翻译中…

Output

翻译中…

Output $T$ lines.

翻译中…

The $i$-th line should contain one string $S'$ obtained by rearranging the characters of $S$ in the $i$-th test case such that $f(S')$ is minimized. If there are multiple such $S'$, any of them will be considered correct.

翻译中…

样例

Input #1
3
see
xxxxxy
abracadabra
Output #1
ese
xxxyxx
abracadabra
For the first test case, the strings $S'$ obtained by rearranging the characters of $S$ are `see`, `ese`, and `ees`. Among these, only `ese` minimizes $f(S')$, so output it. For the second test case, for example, outputting `xxyxxx` will also be considered correct.
题目信息
题号
arc209_b
时间限制
2 s
内存限制
1024 MB

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