#K741. Smallest Lexicographical Sequence

    ID: 34122 Type: Default 1000ms 256MiB

Smallest Lexicographical Sequence

Smallest Lexicographical Sequence

You are given several test cases. In each test case, you are given an integer N followed by N strings. Your task is to form a new string that contains every distinct character that appears in any of the given strings. The resulting string must list these characters in ascending lexicographical order.

Note: For each test case, first read an integer N which denotes the number of strings that follow. Then, for each test case, output a single line containing the lexicographically smallest sequence composed of all distinct characters from the input strings.

Examples:

  • If the test case is: N = 1 and the string is "abc", the output is "abc".
  • If the test case is: N = 2 and the strings are "xyz" and "bcd", the output is "bcdxyz".
  • If the test case is: N = 3 and the strings are "abc", "bcd", and "cde", the output is "abcde".
  • If the test case is: N = 2 and the strings are "aaa" and "bbb", the output is "ab".

You need to process multiple test cases. The input starts with an integer T indicating the number of test case groups, followed by T blocks. Each block begins with an integer that specifies how many strings are in that test case, and then that many strings follow. For each test case, output the computed sequence on a new line.

The lexicographical order is defined in the usual way, and the answer must be produced using the following LaTeX formatted concept for clarity:

$$\text{Answer} = \text{sorted}(\bigcup_{i=1}^{N} \{\text{characters in string}_i\})$$

inputFormat

The first line of the input contains an integer T representing the number of test cases.

For each test case, the first line contains a single integer N (the number of strings). The following N lines each contain a non-empty string.

Input Format Example:

T
N
s1
s2
...
sN

outputFormat

For each test case, output a single line containing the lexicographically smallest sequence consisting of all distinct characters present in the given strings.

Output Format Example:

result_1
result_2
... 
result_T
## sample
1
1
abc
abc

</p>