The first line is the number of cases.
For each case, there will be the content of the dictionary, which end with a line contains a single "#". Each line of the dictionary will not contain more than 2,000 characters, ant it will contain no more than 100,000 words. In a dictionary, Words are only splited by a single space. A word MAY in two lines.
Then followed by a line contain a integer T, indicates the number of scrolls. For each scroll, First line is an integer m meaning the number of magic words that the scroll must contain, then followed by m such magic words. The length of a word will not exceed 20.