HTHL
The Young Hackers Club has created a new language for web pages. In this language, tags have no attributes, and spaces are not allowed within the tags. Specifically, let's define the opening tag in HTHL (Hyper Text Hackers' Language) as:
"<", tag name, ">"
and the closing tag as:
"</", tag name, ">"
where tag name is any sequence of Latin letters and digits, with a maximum length of 100 characters. Here are some examples of HTHL tags:
<b> <par> <hthl> <hacker2> <super>
</b> </par> </hthl> </hacker2> </super>
While developing a browser to view their pages, the young hackers faced the challenge of searching for words on the page. Some tags (like <b>, <i>, and <u>) and their corresponding closing tags (like </b>, </i>, and </u>) do not interrupt a word. For instance, when searching for the word hello, the sequence
h<b><i>el</i></b>o
should be recognized as a match. Your task is to assist the young hackers in solving this search problem.
Input
The first line contains the number k (0 ≤ k ≤ 100) of tag names that do not break a word. The following k lines list these tag names.
The next line contains the number n (1 ≤ n ≤ 100) of lines on the HTHL page where the search will be performed. The subsequent n lines contain the page text, with each line being no longer than 250 characters.
The next line specifies the number of queries m (1 ≤ m ≤ 100). Following this are m lines, each containing a word to search for in the document. A word is any sequence of Latin letters and digits, with a maximum length of 250 characters.
It is guaranteed that the HTHL page is correctly formatted, meaning all symbols "<", "/", and ">" are used exclusively in tags, and all tags are properly written.
Case differences should be ignored.
Output
Output m lines, each indicating the line number on the page where the word first appears, or 0 if the word does not appear on the page (line numbering starts from 1).