Unfortunately, SPAM messages are becoming more and more common. Some of them can multiply, because they ask you to forward them to everyone you know. Some SPAM messages wish you good luck, others promise you will become rich, and others simply remind you how important it is to tell your friends how much you care. Here is a typical SPAM message.
From: Alice
To: Bob, Mary, Julia, PaulHi, this is a good-luck email. I wish for you to become a millionaire, but
that is up to you. If you
* send this email to 10 or more people, you will become a millionaire;
* send this email to 5 or more people, you will become rich;
* send this email to fewer than 5 people, you will stay poor.
As I said, it is up to you. Write your email and get rich! :-)Alice
People usually react to a SPAM message in one of two ways:
In this problem we assume that everyone loves SPAM, so everyone who receives a message forwards it to all of the friends whose email address they know. Nobody, however, forwards the same message more than once, and nobody sends a message to themselves.
Each SPAM message produces a different effect depending on how many friends you forward it to. A SPAM message defines two threshold values $T_1$ and $T_2$ ($T_1 \le T_2$) and three attributes $A_1$, $A_2$, and $A_3$. Let $T$ be the number of messages a person forwards for a given SPAM (that is, the number of friends they send it to; if they never receive that SPAM, then $T = 0$). The person acquires the attribute:
You are given a group of people and, for each person, the set of friends whose email address they know. You are also given a set of distinct SPAM messages, each with its thresholds, its three attributes, and the person who originates it. For each person, determine the attributes they acquire from every SPAM message. You may assume that every SPAM originator has at least one friend.
The input contains several test cases. The first line of a test case contains an integer $N$, the number of people in the group ($2 \le N \le 20$). People are identified by integers from $1$ to $N$.
The next $N$ lines describe friendships: the $i$-th of these lines lists the friends of person $i$ — the people whose email address person $i$ knows. Each such line is a list of integers $F$ ($1 \le F \le N$, $F \ne i$) terminated by a single $0$.
Then comes the description of the SPAM messages (at most $100$ of them), one per line. Each line contains an integer $P$ — the person who originates the SPAM ($1 \le P \le N$) — followed by the two threshold values $T_1$ and $T_2$, and the three attributes $A_1$, $A_2$, and $A_3$ (each attribute is a single word of at most $20$ letters). The list of SPAM messages ends with a line containing a single $0$.
Finally, $N$ lines follow; the $i$-th contains the name of person $i$ (a single word of at most $20$ letters).
The end of the input is indicated by $N = 0$.
For each test case, output one line for each person, in the order the people appear in the input. Each line contains the person's name followed by a colon and a space, and then the attributes that person acquired, in the same order as the SPAM messages appear in the input. Each attribute is followed by a single space.