Card Solitaire

Time limit5sMemory limit128 MB

Problem

Numbered cards are split into several groups, and each group is laid out in a row. On each turn, choose one group that still has cards and move the front card of that group to the back of the answer group. The next card in the chosen group then becomes its new front card.

Once a card is placed in the answer group, it cannot be removed, replaced, or reordered. The game ends when every card has been placed in the answer group.

Treating each answer group as a sequence, the better answer is the one that is lexicographically smaller. Find the lexicographically smallest answer group that can be made.

Input

The first line contains the number of groups N. (1 <= N <= 1,000)

Each of the next N lines starts with the number of cards L in that group, followed by the L card values in front-to-back order. (1 <= L <= 1,000)

Every card value is a positive integer at most 100,000,000.

Output

Print the numbers in the lexicographically smallest answer group on one line, separated by spaces.