Baby's First Suffix Array Problem

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

문제

A suffix array for string ss of length nn is a permutation sasa of integers from 11 to nn such that s\[sa_1..n],s\[sa_2..n],,s\[sa_n..n]s\[sa\_1.. n], s\[sa\_2..n], \dots, s\[sa\_n..n] is the list of non-empty suffixes of ss sorted in lexicographical order. The rank table for suffixex of ss is a permutation rankrank of integers from 11 to nn such that rank_sa_i=irank\_{sa\_i} = i.

Kotori has a string s=s_1s_2s_ns=s\_1s\_2\dots s\_n. She would like to ask mm queries. And in the ii-th query, a substring x=s\[l_i..r_i]x=s\[l\_i..r\_i] of ss is given, Kotori would like to know the rank of suffix s\[k_i..r_i]s\[k\_i..r\_i] of xx.

Note s\[l..r]s\[l..r] means the substring of ss which starts from the ll-th position and ends at the rr-th position, both inclusive.

입력

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (1n,m5×1041 \le n, m \le 5 \times 10^4) -- the length of the string and the number of queries.

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

Each of the next mm lines contains three integers l_il\_i, r_ir\_i and k_ik\_i (1l_ir_in,l_ik_ir_i1 \le l\_i \le r\_i \le n, l\_i \le k\_i \le r\_i) denoting a query.

It is guaranteed that neither the sum of nn or the sum of mm of all test cases will exceed 5×1045 \times 10^4.

출력

For each query output one line containing one integer denoting the answer.