Baby's First Suffix Array Problem
题号:NC216001
时间限制:C/C++/Rust/Pascal 5秒,其他语言10秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

A suffix array for string s of length n is a permutation sa of integers from 1 to n such that is the list of non-empty suffixes of s sorted in lexicographical order. The rank table for suffixex of s is a permutation rank of integers from 1 to n such that .

Kotori has a string . She would like to ask m queries. And in the i-th query, a substring of s is given, Kotori would like to know the rank of suffix of x.

Note means the substring of s which starts from the l-th position and ends at the r-th position, both inclusive.

输入描述:

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

The first line contains two integers n and m () -- the length of the string and the number of queries.

The second line contains a string s of length n consisting only of lowercase English letters.

Each of the next m lines contains three integers l_i, r_i and k_i () denoting a query.

It is guaranteed that neither the sum of n or the sum of m of all test cases will exceed .

输出描述:

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

输入

复制
2
10 4
baaabbabba
2 8 3
1 1 1
2 3 2
2 5 4
20 3
cccbccbadaacbbbcccab
14 17 16
3 20 17
17 20 18

输出

复制
2
1
2
3
4
15
3