The UPF Hacklab offers students a space where they can share knowledge to develop interests and skills in a multidisciplinary way. But each time an interest group is created, all members of Hacklab receive an email, spamming students who are not part of the interest group.
In order to automatize the mailing process, Alice has decided to create a repository of students together with their interests.
The input consists of several test cases. Each test case starts with an integer of students. The following lines contain the name of each student, the number of topics he or she is interested in and the corresponding names of the topics.
Then, an integer of meetings will take place in the Hacklab. Each meeting will start with the word “Union” or “Intersection”, followed by the number of topics and the name of each topic. “Union” means that all students interested in any of the topics are invited, while “Intersection” means that only students interested in all topics are invited.
For each test case, output the number of students we have to send email to and their respective names in lexicographical order.
Input
3 John 1 Science Antoine 2 Science Math Bob 2 Literature Math 2 Intersection 2 Science Math Union 2 Science Literature
Output
1 Antoine 3 Antoine Bob John