Prefix-free Queries

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

문제

Let C(s_1,s_2,,s_k)C (s\_1, s\_2, \ldots, s\_k) be the number of ways to construct a prefix-free set from the multiset of strings s_1,s_2,,s_k{s\_1, s\_2, \ldots, s\_k}. A prefix-free set is a set of distinct strings in which there are no two strings such that one of these strings is a prefix of another one. In particular, an empty set is a valid prefix-free set. For example, if for any iji \neq j, s_is\_i is not a prefix of s_js\_j, then C(s_1,,s_k)=2kC (s\_1, \ldots, s\_k) = 2^{k}.

Note that we count not the sets themselves, but the ways to construct such sets: the number of ways to choose a subset of indices out of 1,2,,k\\{1, 2, \ldots, k\\} such that the strings with these indices form a prefix-free set. For example, C(C("aa", "aa", "a", "a") =5) = 5: the five ways are to construct an empty set, a set containing the first string, a set containing the second string, a set containing the third string, and a set containing the fourth string.

You are given a string ss consisting of nn lowercase English letters, and qq queries. Let s\[l,r]s\[l, r] be the substring s_ls_l+1s_r1s_rs\_{l} s\_{l + 1} \ldots s\_{r - 1} s\_r. For each query denoted as "kk mm l_1l\_1 r_1r\_1 l_2l\_2 r_2r\_2 \ldots l_kl\_k r_kr\_k", print one integer: the value C(s\[l_1,r_1],s\[l_2,r_2],,s\[l_k,r_k])C (s\[l\_1, r\_1], s\[l\_2, r\_2], \ldots, s\[l\_k, r\_k]), taken modulo mm.

입력

The first line contains two integers: nn, the length of ss, and qq, the number of queries to answer (1n41051 \le n \le 4 \cdot 10^{5}, 1q41051 \le q \le 4 \cdot 10^5).

The second line contains a string ss of length nn consisting of lowercase English letters.

Next qq lines contain queries, one query per line. Each query has the form "kk mm l_1l\_1 r_1r\_1 l_2l\_2 r_2r\_2 \ldots l_kl\_k r_kr\_k" (1k41051 \le k \le 4 \cdot 10^{5}, 2m1092 \le m \le 10^{9}, 1l_jr_jn1 \le l\_j \le r\_j \le n).

The total sum of all kk over all queries does not exceed 41054 \cdot 10^5.

출력

For each query, print a line containing a single integer: the value C(s\[l_1,r_1],s\[l_2,r_2],,s\[l_k,r_k])C (s\[l\_1, r\_1], s\[l\_2, r\_2], \ldots, s\[l\_k, r\_k]), taken modulo mm.