#P9863. String

    ID: 8085 传统题 6000ms 512MiB 尝试: 4 已通过: 1 难度: 9 上传者: 标签>字符串后缀自动机数据结构线段树数学CF2600树形DP2023“钉耙编程”中国大学生算法设计超级联赛(6)

String

String

Problem Description

Alice and Bob are playing a string game. Alice has a string SS, Bob has a string TT, in each round of the game, Bob will choose a string interval T[l,r]T[l,r] in TT , Alice needs to find a string interval S[l,r]S[l',r'] in SS to make T[l,r]T[l,r] is a substring of S[l,r]S[l',r']. We define an interval of pairs [l,r][l,r]string SS if and only if 1lrSlen1\leq l\leq r\leq S_{len}(SlenS_{len} is the string SS length), all optional intervals of a string are all l,rl, r that satisfy the condition. S[l,r]S[l,r] is a string formed by concatenating the SS string from the llth character to the rrth character in order. A string TT is a substring of the string SS if and only if the string TT can be obtained by removing some characters from the beginning and the end of the string SS (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 TT, how many intervals Alice can choose from the string SS 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 TT, so you will need to answer multiple sets of questions.

Input

For the first line,input a positive integer T(1T5)T(1\le T\le 5), representing the total number of test data. For each test data,the first line contains two positive integers n,q(1n,q100000)n,q(1\leq n,q\leq 100000), which represent the length of the string and the number of queries. The second line contains a string of length nn representing the SS string owned by Alice. The next qq lines, each line contains a string, representing the query string TT. It is guarantees that the length of all query strings does not exceed 10610^6 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 998244353998244353.

Sample Input

1
4 4
aaba
a
aa
ab
cab

Sample Output

9
7
332748124
166374062

Hint

For the third query, BobBob can choose from three intervals of [1,1][2,2][1,2][1,1][2,2][1,2], and the corresponding AliceAlice has 9,6,49,6,4 intervals to choose from, So the answer is 9+6+43\frac{9+6+4}{3}

Source

2023“钉耙编程”中国大学生算法设计超级联赛(6)