A big gym network has several branches at different locations. They find it sometimes hard to keep track of the people that have their memberships. They know the name of the people and where their gym is, but they would like to know the list of people for each location.
The first line of the input contains a single integer
nthe number of people who have signed up for a gym membership. The next
nlines contain "
-" separated person's name and the location of the gym where they have their membership. The next line contains a single integer
q, the number of location queries. The following
qlines contain the names of the locations.
The program should print
qlines. Each line should contain space-separated names of people who are attending the gyms at that location.
Input 5 Bob - Green st. 1 Lucy - Park Dr. 25 Anna - Green st. 1 Lucas - Sharon Park Dr. 8 Simon - Sharon Park Dr. 8 3 Sharon Park Dr. 8 Green st. 1 Park Dr. 25 Output Lucas Simon Bob Anna Lucy
Note: The names should be in the order of appearance in the input