278 传统题

[ABC459D] 相邻不同重排 (Adjacent Distinct String)

时间限制
2000ms
内存限制
512MiB
登顶 / 尝试
1/ 1
难度
3

[ABC459D] 相邻不同重排 (Adjacent Distinct String)

Problem Statement

You are given a string SS consisting of lowercase English letters.

Determine whether it is possible to rearrange the characters of SS so that no two adjacent characters are the same, and if so, find one such rearrangement.

You are given TT test cases; solve each.

Input

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

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

The ii-th (1≤i≤T)(1 \le i \le T) test case casei\text{case}_i is given in the following format:

$S$

Output

Output the answers for the test cases in order, separated by newlines.

For each test case, if it is impossible to rearrange SS so that no two adjacent characters are the same, output No.

If it is possible, let S′S' be such a rearrangement and output in the following format:

Yes
$S'$

If there are multiple valid rearrangements of SS, any of them will be accepted.

Example

3
aiiw
doodoo
aabbababcacababaaba
Yes
iwai
No
Yes
ababacabababacababa

Note

  • Constraints:

  • 1≤T≤3×1051 \le T \le 3 \times 10^5

  • SS is a string of length between 11 and 10610^6, inclusive, consisting of lowercase English letters.

  • The total length of SS across all test cases is at most 10610^6.

  • Source: ABC459D