Circle of Friends

No attempts yetTime limit1sMemory limit128 MB

Problem

Grace has measured how strong the friendships are between different Navi, and now she wants to find tightly knit groups of friends. A group of Navi has strength $k$ if every Navi in the group has at least $k$ friends who are also in the group. Friendship is mutual: if A is a friend of B, then B is a friend of A. For each Navi you are asked about, find the strongest and largest circle of friends that Navi can belong to.

Input

The input may contain several independent instances, one after another; each instance is read from scratch.

An instance begins with a line containing GRAPH BEGIN. Each following line describes one Navi: the first name on the line is the Navi, and the remaining names on the same line are that Navi's friends. The line GRAPH END closes the list of friendships.

After GRAPH END, each of the next lines names one Navi to analyze, one name per line. The instance ends at the next GRAPH BEGIN line or at the end of the input.

Some Navi appear only as another Navi's friend and never begin a line of their own; they are still part of the friendship graph.

Output

Print one line for each analyzed Navi, in the same order they were given. On each line, separated by single spaces, print: the Navi's name; the largest strength $k$ for which the Navi belongs to some group of friends of strength $k$; and the members of that group, including the Navi itself, in alphabetical order.

The group must be connected: every member must be reachable from the analyzed Navi through friendships inside the group. First maximize the strength $k$; then, among the strength-$k$ groups the Navi can belong to, output the largest one.

For example, a Navi may belong to a group of strength 3 as well as to several groups of strength 2; because $3 > 2$, the strength-3 group is reported. Another Navi may belong to several groups of strength 1 of different sizes; the largest such group is the one to report.

Hint