The program reads from standard input.
The first line holds the number of kinds of medicine N. (1≤N≤100)
Each of the next N lines holds the symptom the medicine treats Me and the name of the medicine Mn, both as numbers. (0≤Me,Mn≤100) No two medicines share a name, and no two medicines treat the same symptom.
The next line holds the number of symptom lists R. (1≤R≤100)
Each of the next R lines holds a count Li followed by the symptoms S1,S2,…,SLi. (1≤Li≤N, 0≤Sj≤100) The symptoms on one line are distinct.