| Codeforces Round 1083 (Div. 2) |
|---|
| Finished |
There are $$$n$$$ blogs. The $$$i$$$-th blog mentioned $$$l_i$$$ users in order as an array $$$a_i=[a_{i,1},a_{i,2},\ldots,a_{i,l_i}]$$$.
You are going to post all $$$n$$$ blogs. Let us maintain a sequence $$$Q$$$ that describes the list of users you have recently mentioned. You need to perform the following operation exactly $$$n$$$ times:
Find the lexicographically smallest$$$^{\text{∗}}$$$ $$$Q$$$ after all $$$n$$$ operations.
$$$^{\text{∗}}$$$An array $$$x$$$ is lexicographically smaller than an array $$$y$$$ if and only if one of the following holds:
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line contains a single integer $$$n$$$ ($$$1\le n\le 3000$$$) — the number of blogs.
Then $$$n$$$ lines follow, the $$$i$$$-th line starting with an integer $$$l_i$$$ ($$$1\le l_i\le 3000$$$), describing the number of users mentioned in the $$$i$$$-th blog, which is followed by $$$l_i$$$ integers $$$a_{i,1},a_{i,2},\ldots,a_{i,l_i}$$$ ($$$1\le a_{i,j}\le 10^6$$$) — the list of users mentioned in the $$$i$$$-th blog.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3000$$$.
Denote $$$\sum\limits_{i=1}^n l_i$$$ as $$$L$$$. It is guaranteed that the sum of $$$L$$$ over all test cases does not exceed $$$3000$$$.
Denote $$$m$$$ as the number of users mentioned in at least one blog. For each test case, output $$$m$$$ integers $$$Q_1,Q_2,\ldots,Q_m$$$ — the lexicographically smallest $$$Q$$$.
535 1 2 3 4 63 2 5 14 1 9 2 322 1 61 613 6 1 154 2 3 3 45 1 2 4 3 12 4 13 3 3 15 4 3 2 2 254 2 3 1 45 2 5 5 6 55 3 4 7 5 58 3 6 4 3 1 1 5 42 1 1
1 5 2 3 9 6 46 11 61 3 2 41 4 3 2 5 6 7
In the first test case, you can post the blogs as follows:
There is another method to post blogs:
We can see that $$$[1,5,2,3,9,6,4]$$$ is lexicographically smaller than the other one. If we do not post the second blog at the end, the first element of the array will not be $$$1$$$, so $$$[1,5,2,3,9,6,4]$$$ is the lexicographically smallest array $$$Q$$$.
In the second test case, you can post the blogs as follows:
In the third test case, you have to post the only blog, and $$$Q$$$ will become $$$[1,6]$$$.
| Name |
|---|


