Pattern Matching

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

Rikka has nn sets S_1,S_2,,S_nS\_1, S\_2, \ldots, S\_n consisting of lowercase English letters. A pattern p_1p_2p_mp\_1 p\_2 \ldots p\_m of length mm is said to match the sets if there exists an index ii such that all the following conditions hold: p_1S_ip\_1 \in S\_i, p_2S_i+1p\_2 \in S\_{i + 1}, \ldots, p_mS_i+m1p\_m \in S\_{i + m - 1}.

Initially, all sets are empty. Rikka has prepared some operations to make with the sets. Each operation has the form "add character cc into set ii". Each round, Rikka will choose a random operation with equal probability and apply it. A single operation may be chosen and applied more than once.

Find the expected number of rounds until the pattern p_1p_2p_mp\_1 p\_2 \ldots p\_m matches the sets.

입력

The first line contains an integer TT which denotes the number of test cases (1T51 \le T \le 5).

For each test case, the first line contains two integers nn and mm (1mn301 \leq m \leq n \leq 30).

The ii-th of the following nn lines contains a string t_it\_i consisting of lowercase English letters. Each letter t_i,jt\_{i, j} denotes an operation which adds this letter into set ii. Each of these strings is non-empty and contains every possible letter at most once.

The last line of each test case contains the pattern: a string p_1p_2p_mp\_1 p\_2 \ldots p\_m consisting of lowercase English letters.

출력

For each test case, if the pattern will never match the sets, output "1-1". Otherwise, output the integer (pq1)mod998,244,353(p \cdot q^{-1}) \bmod 998\\,244\\,353, where pq\frac{p}{q} is the expected number of rounds.

힌트

For the first sample test case, the expectation is 121+1222+=2\frac{1}{2} \cdot 1 + \frac{1}{2^2} \cdot 2 + \ldots = 2.