Group Of Interest X16299


Statement
 

pdf   zip

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.

Input

The input consists of several test cases. Each test case starts with an integer N500N \leq 500 of students. The following NN lines contain the name of each student, the number of topics 1In101 \leq I_n \leq 10 he or she is interested in and the corresponding names of the topics.

Then, an integer M500M \leq 500 of meetings will take place in the Hacklab. Each meeting will start with the word “Union” or “Intersection”, followed by the number of topics 1T101 \leq T \leq 10 and the name of each topic. “Union” means that all students interested in any of the TT topics are invited, while “Intersection” means that only students interested in all TT topics are invited.

Output

For each test case, output the number of students we have to send email to and their respective names in lexicographical order.

Public test cases
  • 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
    
  • Information
    Author
    Javier Segovia
    Language
    English
    Official solutions
    C++
    User solutions