Sub-dictionary

No attempts yetTime limit1sMemory limit128 MB

Problem

In this problem, a dictionary holds several words sorted in ascending alphabetical order, together with each word's meaning (its definition). Every definition is written using only words that appear in the same dictionary. If a dictionary defines $N$ words, then—counting both the defined words and the words used inside definitions—there are exactly $N$ distinct words in total. Moreover, no word ever appears in its own definition.

A sub-dictionary is formed by choosing only some of the original dictionary's words, and it must itself be a complete dictionary. That is, every word used in the definition of any word inside the sub-dictionary must also be defined inside that same sub-dictionary, so that the sub-dictionary can stand on its own as an independent dictionary.

A project to teach a computer language is underway. First we feed it a dictionary to teach it words; then, when we give it a sentence made only of those words, the computer interprets the sentence and performs the desired action.

To let the computer learn words on its own, we first teach it by hand all the words of some sub-dictionary until it understands them. From then on the computer learns by itself: whenever it already knows every word used in some word's definition, it can learn that new word too, and each newly learned word can in turn be used to learn others. For example, for the computer to understand the word "xyz", it must already know every other word used in the definition of "xyz".

Write a program that finds the smallest sub-dictionary we must teach by hand so that the computer can then learn every word of the dictionary on its own.

Input

The input consists of several test cases.

The first line of each test case contains the number of words defined in the dictionary, $n$ ($1 \le n \le 100$).

Each of the next $n$ lines gives the definition of one word. The first word on a line is the word being defined, and the remaining words on that line are the words used in its definition; that is, to understand the first word you must know all of the remaining words. A single definition uses at most $30$ words.

All words are separated by spaces, consist only of lowercase English letters, and are shorter than $25$ characters.

The end of the input is marked by a line containing $n = 0$, which is not processed.

Output

For each test case, print two lines. On the first line, print the number of words in the smallest valid sub-dictionary. On the second line, print those words in ascending alphabetical order, separated by spaces. If the smallest sub-dictionary is empty, the second line is printed as an empty line.