CF832E.Vasya and Shifts

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya has a set of 4n4n strings of equal length, consisting of lowercase English letters "a", "b", "c", "d" and "e". Moreover, the set is split into nn groups of 44 equal strings each. Vasya also has one special string aa of the same length, consisting of letters "a" only.

Vasya wants to obtain from string aa some fixed string bb , in order to do this, he can use the strings from his set in any order. When he uses some string xx , each of the letters in string aa replaces with the next letter in alphabet as many times as the alphabet position, counting from zero, of the corresponding letter in string xx . Within this process the next letter in alphabet after "e" is "a".

For example, if some letter in aa equals "b", and the letter on the same position in xx equals "c", then the letter in aa becomes equal "d", because "c" is the second alphabet letter, counting from zero. If some letter in aa equals "e", and on the same position in xx is "d", then the letter in aa becomes "c". For example, if the string aa equals "abcde", and string xx equals "baddc", then aa becomes "bbabb".

A used string disappears, but Vasya can use equal strings several times.

Vasya wants to know for qq given strings bb , how many ways there are to obtain from the string aa string bb using the given set of 4n4n strings? Two ways are different if the number of strings used from some group of 44 strings is different. Help Vasya compute the answers for these questions modulo 109+710^{9}+7 .

输入格式

The first line contains two integers nn and mm ( 1<=n,m<=5001<=n,m<=500 ) — the number of groups of four strings in the set, and the length of all strings.

Each of the next nn lines contains a string ss of length mm , consisting of lowercase English letters "a", "b", "c", "d" and "e". This means that there is a group of four strings equal to ss .

The next line contains single integer qq ( 1<=q<=3001<=q<=300 ) — the number of strings bb Vasya is interested in.

Each of the next qq strings contains a string bb of length mm , consisting of lowercase English letters "a", "b", "c", "d" and "e" — a string Vasya is interested in.

输出格式

For each string Vasya is interested in print the number of ways to obtain it from string aa , modulo 109+710^{9}+7 .

输入输出样例

  • 输入#1

    1 1
    b
    2
    a
    e
    

    输出#1

    1
    1
    
  • 输入#2

    2 4
    aaaa
    bbbb
    1
    cccc
    

    输出#2

    5
    

说明/提示

In the first example, we have 44 strings "b". Then we have the only way for each string bb : select 00 strings "b" to get "a" and select 44 strings "b" to get "e", respectively. So, we have 11 way for each request.

In the second example, note that the choice of the string "aaaa" does not change anything, that is we can choose any amount of it (from 00 to 44 , it's 55 different ways) and we have to select the line "bbbb" 22 times, since other variants do not fit. We get that we have 55 ways for the request.

首页