#C4649. Minimal Preparation Time for Ingredients

    ID: 48210 Type: Default 1000ms 256MiB

Minimal Preparation Time for Ingredients

Minimal Preparation Time for Ingredients

You are given an integer t representing the number of test cases. Each test case consists of a string representing ingredients. For each test case, you need to determine a subsequence of ingredients by taking the unique characters from the string and then sorting them in ascending order. Additionally, compute the total preparation time by summing up the preparation time for each unique ingredient.

The preparation time for a given ingredient c is defined as its position in the alphabet. Formally, the time is given by:

\( time(c)=\text{ord}(c)-\text{ord}('a')+1 \)

Output the sum of the preparation times along with the sorted subsequence of unique ingredients. Each test case's output should be on a separate line in the format:

sum subsequence

where sum is the total preparation time and subsequence is the sorted string of unique ingredients.

inputFormat

The first line of input contains a single integer t representing the number of test cases. This is followed by t lines, each containing a non-empty string of lowercase English letters, representing the ingredients for that test case.

For example:

3
abcd
bcde
aabbccdd

outputFormat

For each test case, output a single line containing two items separated by a space: the minimal preparation time (an integer) and the corresponding subsequence of unique ingredients (a string) obtained by sorting the unique letters from the input string.

For example, for the sample input above, the output should be:

10 abcd
14 bcde
10 abcd
## sample
3
abcd
bcde
aabbccdd
10 abcd

14 bcde 10 abcd

</p>