Problem 3

Mendelev's Lines

Gregor Mendel was an Austrian monk. His experiments showed how inheritance works.

We shall simulate a simplied genetic model for this problem. Given a list of people who were tested for a particular genetic trait several generations ago and the outcome of the test, the program should list descendants who come from a line of individuals who do not have this genetic trait.

Input

The input consists of several lines. The first line will number those people who were tested. For each, a name and a test result will follow. This test result is either "PRESENT" or "NOT PRESENT".

The next line will list the number of descendants the tested group had. For each descendant, that decendant's name is listed alongside its parents names. The format for this line is:

[DESCENDANT_NAME]:[PARENT1_NAME],[PARENT2_NAME]
NOTE: Names may contain spaces

Output

The output will list the names of decendants (one per line) who come from a line of individuals who do not have the genetic trait which their ancestors were tested for (ie. those individuals designated NOT PRESENT).

Example

Input

4
John Smith
NOT PRESENT
Mary Jones
NOT PRESENT
Edel Williams
PRESENT
Alan Wood
NOT PRESENT
5
Tom Smith:Mary Jones,John Smith
Anne Smith:Mary Jones,John Smith
Kid1 Wood:Edel Williams,Alan Wood
Kid2 Wood:Edel Williams,ALan Wood
New kid:Anne Smith,Kid2 Wood

Output

Tom Smith
Anne Smith