Mike and Friends
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

    What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercase English letters. What is double strange that a phone number can be associated with several bears!
    In that country there is a rock band called CF consisting of n bears (including Mike) numbered from 1 to n.
    Phone number of i-th member of CF is s_i. May 17th is a holiday named Phone Calls day. In the last Phone Calls day, everyone called all the numbers that are substrings of his/her number (one may call some number several times). In particular, everyone called himself (that was really strange country).
    Denote as call(i, j) the number of times that i-th member of CF called the j-th member of CF.
    The geek Mike has q questions that he wants to ask you. In each question he gives you numbers l, r and k and you should tell him the number

输入描述:

The first line of input contains integers n and q ( and ).
The next n lines contain the phone numbers, i-th line contains a string s_i consisting of lowercase English letters ().
The next q lines contain the information about the questions, each of them contains integers l, r and k ( ≤ n and ).

输出描述:

Print the answer for each question in a separate line.
示例1

输入

复制
5 5
a
ab
abab
ababab
b
1 5 1
3 5 1
1 5 2
1 5 3
1 4 5

输出

复制
7
5
6
3
6

备注:

来自codeforces:http://codeforces.com/contest/547/problem/E