#C4568. Merge and Sort Lists

    ID: 48120 Type: Default 1000ms 256MiB

Merge and Sort Lists

Merge and Sort Lists

You are given several lists of integers. Your task is to merge these lists, remove duplicate elements, and output a sorted list of unique integers. In mathematical terms, if you have lists \(L_1, L_2, \dots, L_n\), you need to compute \(S = \mathrm{sorted}(\{ x \mid x \in L_1 \cup L_2 \cup \cdots \cup L_n \})\).

The solution should be efficient and handle multiple test cases. All input is to be read from stdin and all output should be written to stdout.

inputFormat

The input begins with an integer T representing the number of test cases. For each test case:

  • The first line contains an integer N, the number of lists.
  • Each of the next N lines starts with an integer M denoting the number of elements in that list, followed by M space-separated integers.

All inputs are provided via standard input (stdin).

outputFormat

For each test case, output a single line containing the sorted unique integers separated by a space. The output should be written to standard output (stdout).

## sample
1
4
3 1 3 5
3 2 4 6
4 1 2 3 4
3 5 7 8
1 2 3 4 5 6 7 8

</p>