Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.
Problem hidden

FULLNAME - The Full Name


Muhammad is so curious about his family history and ancestors, he wants to know the longest name in his family. So he went to his village to find the oldest man in the family to ask him for that name. He kept on searching for the oldest man until he found him, his name was El-sheikh Abdullah. Muhammad asked El-sheikh Abdullah about the longest name he knows in the family, but the memory of El-sheikh Abdullah is not so good and he can’t remember the full name. The only thing he can remember is the relationship between the members of the family, so he told Muhammad the names of the family members and the relationship between the members. Now Muhammad has to collect this information and try to get the longest name in the family. It is a difficult task because the number of family members is big. Luckily for Muhammad, he has a friend in acmASCIS named Sharaf. So he asked him to design a program that solves his problem and get him the longest name in the family. Sharaf said "I know exactly who can solve your problem, today is the First year students' contest where there are some special contestants who can help you solve it".

Now it’s your turn to solve this problem. You'll be given a series of family members' names, and a series of relations between them and your job is to find the longest name in the family.

Input

The first line of input is the number of test cases N. Each test case starts with line containing the number of Family members M. Then follows M lines, each line will contain a sentence in this format "Person#=X". where "#" is the person number, and "X" is the person name and (2<=M<=50). Next line of input will be the number of family relationships K. then follows K lines, each line will contain a sentence "Person# R Person#" where "R" is the family relationship and "#" is the person number and (0<K<=M).

Family relationships:

S = Son

F = Father

GF = Grand father

GS = Grandson

GGF = Great Grandfather

GGS = Great Grandson

Notes:

1) The Family relationships may not include all family members mentioned in the input.

2) For each test case there is a valid & unique solution.

3) Each case must have a Family relationship "Son" or "Father", and assume that there is only one son for each father, and one GGS for each GGF, and so on.

Output

For each test case print (without quotes) "Case_#i:_X" where "X" the full name and "i" is the number of the test case (starting with 1) and "_" is white space. Each output should be in separate line. Full name means the longest series of names (not words or characters) sperated by one space.

Example

Input:
3
4
person3=Mohamed
person2=Abd El Ghafour
person1=Mohamed
person4=ALi
2
person3 S person4
person1 F person4
5
person1=Khaled
person3=Ahmed
person4=Hatem
person2=Mahmoud
person5=Mahmoud
4
person5 GF person2
person3 F person5
person1 GGS person4
person2 S person1
4
person1=Sharaf
person2=El Saeed
person3=Mohamed
person4=Mohamed
3
person1 F person2
person2 F person3
person3 F person4
Output:
Case #1: Mohamed Ali Mohamed
Case #2: Mahmoud Khaled Mahmoud Ahmed Hatem
Case #3: Mohamed Mohamed El Saeed Sharaf
4

Added by:Sharaf
Date:2013-02-07
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:2013 acmASCIS Level 1 Contest
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.