#P11091. [2016杭电多校]Generator

[2016杭电多校]Generator

Generator

Problem Description

You are given nn different integer sequences. Each sequence has the same length LL, and also all integers in these sequences are from 1 to mm . There is a random machine that generates a random number sequence. It generates a random number from 1 to mm every second. When all nn sequences are generated as a consecutive subsequence of the sequence the machine generated, the machine is stopped immediately. Now your task is to calculate the expected stopping time.

Input

There are multiple test cases. The first line of the input contains an integer TT, the number of test cases. Each test case begins with 3 positive integers$n(1\leq n\leq 15),m(1\leq M\leq 100,L(1\leq L\leq 20000)$, which are described above. The next line will contain m positive integers a1,a2,,ama_1,a_2,\cdots ,a_m, which describes probability distribution of the dice. This means, the machine will generate 1 with probability a1(a1+a2++am)\frac{a_1}{(a_1+a_2+\cdots +a_m)} , 2 with probability a2(a1+a2++am)\frac{a_2}{(a_1+a_2+\cdots +a_m)}, and so on. The total sum of aia_i does not exceeds 1000000000. Each of the next nn lines contains a sequence of length LL. The total sum of n×Ln\times L over all test cases will not exceed 777777.

Output

For each test case, please calculate the answer as an irreducible fraction AB\frac{A}{B} and output (A×B1 mod 1000000007A\times B^{-1}\ mod\ 1000000007) in a single line. Here B1B^{-1} is the multiplicative inverse of BB modulo 1000000007. The input guarantees that BB and 1000000007 is relatively prime.

Sample Input

1
1 2 2
1 1
1 1

Sample Output

6

Author

金策工业综合大学(DPRK)

Source

2016 Multi-University Training Contest 9