The archaeologist Mr. Ford Trunkings has uncovered the ruins of the ancient Velulu tribe deep in Africa. The Velulu were remarkably advanced for their age and even had an alphabet of their own, but a glacial period roughly 20,000 years ago destroyed their civilization and their writings were almost entirely lost.
Your job is to help decipher the surviving Velulu texts. The trouble is that Velulu writing uses no spaces at all: every text is a single unbroken string of letters, with all of its words run together.
The researchers have already compiled a draft dictionary of the language. Splitting a text into dictionary words alone, however, yields an enormous number of possibilities for almost any text of reasonable length. To narrow things down they also reconstructed a set of sentence construction rules, each describing the order in which parts of speech may appear within a single sentence.
Using the dictionary together with these rules, determine in how many ways the given text can be parsed.
The first line contains three integers $n$, $m$ and $k$ ($1 \le n \le 5000$, $1 \le m \le 10$, $1 \le k \le 10$): the number of dictionary words, the number of sentence construction rules, and the number of distinct parts of speech.
Each of the next $n$ lines describes one word. The line starts with the word itself — a non-empty string of fewer than 20 lowercase English letters — followed by an integer $k_i$ ($1 \le k_i \le 10$) and then $k_i$ integers $a_{i1} < a_{i2} < \dots < a_{i k_i}$ ($1 \le a_{ij} \le k$) in strictly increasing order, the parts of speech this word can stand for. Each word appears exactly once, and the words are listed in arbitrary order.
Each of the next $m$ lines describes one construction rule. The line starts with an integer $l_i$ ($1 \le l_i \le 10$), the number of words in this kind of sentence, followed by $l_i$ integers $b_{i1}, b_{i2}, \dots, b_{i l_i}$ ($1 \le b_{ij} \le k$): the parts of speech required at each position, in order. No rule is repeated.
The last line contains the text to decipher: a non-empty string of fewer than 1000 lowercase English letters.
Print a single line with the number of distinct parsings of the text. If that number is greater than $10^{18}$, print TOO MANY instead. If the text cannot be parsed at all, print 0.
A parsing consists of:
Two parsings are considered different if they differ in the word split, in the grouping into sentences, or in the rule chosen for any sentence. (In particular, one and the same sequence of words is counted once for each construction rule it satisfies.)