#C8233. Lexicographical Combinations

    ID: 52193 Type: Default 1000ms 256MiB

Lexicographical Combinations

Lexicographical Combinations

You are given a string \(s\) containing unique alphanumeric characters. Your task is to generate all possible distinct combinations of the characters of \(s\) and then arrange these combinations in lexicographical (dictionary) order. Each combination should be printed as a continuous string and the combinations for a given input string should be printed as a comma separated list.

For example, if \(s = \texttt{abc}\), then the valid combinations are: \(a, ab, abc, ac, b, bc, c\).

Note: A combination is defined as a selection of one or more characters from the string, keeping the original order. The lexicographical order is based on the standard string comparison.

inputFormat

The input is given via stdin in the following format:

T
s1
s2
...
sT

Where:

  • T is an integer representing the number of test cases.
  • Each of the next T lines contains a string s with unique alphanumeric characters.

outputFormat

For each test case, print a single line to stdout with all possible distinct combinations of characters of the given string, arranged in lexicographical order and separated by commas.

## sample
1
abc
a,ab,abc,ac,b,bc,c

</p>