The input consists of several cases, each followed by a blank line.
Each test case starts with three integers N , M and K (1<=N<=1000, 1<=M<=5000, 1<=K<=100) , the number of extracts from the book, the number of assumptions and the number of theories, respectively.
The following part describes extracts and assumptions. Extracts are always described before assumptions. Each description starts with one string S , the name of the extract / assumption, and an integer T in the next line, the number of different explanations you have come up with; T lines follow, on each line there is a string X , the explanation which leads to another assumption / theory.
The next part of test case consists of K descriptions of theories. Each description starts with one string S , the name of the theory, followed by one integer P , the value which you have assigned to this theory.
Two successive descriptions are separated by a line with one single character `-'. It is guaranteed that the total numbers of explanations which extracts and assumptions have does not exceed 50000, and you may assume every string's length is less or equal to 20, and only consists of letters from alphabet and numbers 0...9 .
N = 0 , M = 0 , K = 0 indicates the end of input file and should not be processed by your program.