Problem L

The spaceport likes collecting data on its visitors. We know that there are $p$ nearby planets that generate all traffic in and out of the spaceport. Each planet contains $n$ species and every ship contains $m$ passengers of a particular species. No two planets contain the same species.

Can you help identify how many visitors from each planet come across the spaceport?


Input begins with a number $2\le p\le 15$, the number of planets whose ships are known to frequent the spaceport. Then $p$ lines follow: each line contains a unique planet name $P$ (from one to six uppercase ASCII letters), the number of alien species on the planet $1\le n\le 12$, and $n$ words indicating the names of those species. Each species name $s_ i$ is a string of one to six uppercase ASCII letters.

The next line contains an integer $1\le v\le 15$, indicating the number of visiting spacecraft. The next $v$ lines contain an integer $1\le m\le 12$, where $m$ is the number of visitors, and a word $r$ which is the name of their species, which live on one of the $p$ planets.


Print, in alphabetical order, each planet’s name followed by the number of incoming visitors from that planet.

Sample Input 1 Sample Output 1
A 2 X Y
B 2 E F
C 4 Z W L K
3 X
6 Y
2 Z
5 E
A 9
B 5
C 2

Please log in to submit a solution to this problem

Log in