#P9863. String
String
String
Problem Description
Alice and Bob are playing a string game. Alice has a string , Bob has a string , in each round of the game, Bob will choose a string interval in , Alice needs to find a string interval in to make is a substring of . We define an interval of pairs string if and only if ( is the string length), all optional intervals of a string are all that satisfy the condition. is a string formed by concatenating the string from the th character to the th character in order. A string is a substring of the string if and only if the string can be obtained by removing some characters from the beginning and the end of the string (or not). Both Alice and Bob find this game too boring, and they want to know if Bob randomly chooses one of all the intervals in the string , how many intervals Alice can choose from the string and such that the string selected by Bob is a substring of the string selected by Alice. The game will be played multiple times, and in each round, Bob will change the string , so you will need to answer multiple sets of questions.
Input
For the first line,input a positive integer , representing the total number of test data. For each test data,the first line contains two positive integers , which represent the length of the string and the number of queries. The second line contains a string of length representing the string owned by Alice. The next lines, each line contains a string, representing the query string . It is guarantees that the length of all query strings does not exceed in one test. It is guaranteed that the input string contains only English lowercase letters.
Output
For each query, output a line with a positive integer representing the expected number, and the answer modulo .
Sample Input
1
4 4
aaba
a
aa
ab
cab
Sample Output
9
7
332748124
166374062
Hint
For the third query, can choose from three intervals of , and the corresponding has intervals to choose from, So the answer is
Source
2023“钉耙编程”中国大学生算法设计超级联赛(6)