Namgyu takes a personality diagnostic test. The test consists of several questions, and each question offers 5 activities as its choices. For every question the taker must pick exactly one activity: the one they most prefer.
How would you spend a free afternoon?
(a) League of Legends
(b) The Binding of Isaac
(c) Bothering Jaehyuk, who is coding next to you
(d) Not studying, even though there is an exam tomorrow
(e) Sleeping
The 5 activities in each question are drawn at random from a large pool of activities, so the same activity (for example, "Sleeping") may appear again across several questions.
The activity Namgyu picks in a question is preferred over each of the other four activities in that same question. In other words, if Namgyu picks A out of A, B, C, D, E, then A is preferred over each of B, C, D, and E. Preference is transitive: if X is preferred over Y in one question and Y is preferred over Z in another, then X is also preferred over Z.
Namgyu answered carelessly, so contradictions appeared. For two activities X and Y, if both "X is preferred over Y" and "Y is preferred over X" can be derived, then X and Y are said to contradict each other.
From the given answer data, partition all activities that appear in the test into groups. Two activities belong to the same group if and only if they contradict each other. (Equivalently, group together all mutually contradicting activities; the partition is unique.)
The input consists of several test cases and ends with a line containing 0.
The first line of each test case contains the number of questions $N$. Each of the next $N$ lines describes one question: it first lists 5 distinct activity names, followed by the name of the activity Namgyu chose for that question. The chosen activity is always one of the 5 activities on that line. Every activity name is a single uppercase letter.
For each test case, print the resulting partition. Print one group per line, with the activities in that group in alphabetical order separated by single spaces. Order the groups alphabetically by the alphabetically-first activity in each group. Print only the activities that appear in the test.
Print one blank line between the outputs of consecutive test cases.