HRY and repeaters
题号:NC25452
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

-What is the essence of human beings!
-What is the essence of human beings!
-What is the essence of human beings!
This conversation happens every day, as we can see that the essence of human beings is repeaters.
One day HRY is chatting with n repeaters. Soon the conversation became a mess because everyone begins to repeat. Some repeaters repeat a word many times, some repeaters with low quality make spelling mistakes, and some are repeating other repeaters. Now, given the sentence every repeater says, HRY wants to know that given a word, how many times the repeaters from l to r has repeated it? Assume that the sentence spoken by a repeater is S with length n, the word is string T with length m, the times the repeater repeats this word is defined as the number of different positions k where .

输入描述:

The first line contains an integer n, indicating the number of repeaters.
The next n lines each contains a string S_i, which is the sentence spoken by the ith repeater.
The next line contains an integer Q, indicating the number of queries.
The next Q lines each contains two integers l',r', and a string T_i. Pay attention, you should do following operations to get the real l,r :


means bitwise xor operation, lastans is the ans of last query, if last query not exist, lastans=0.
.
All strings contain only lowercase letters. It is guaranteed that the total length of S_i does not exceed 300000, the total length of T_i does not exceed 300000.

输出描述:

For each of the Q queries, output a line which contains an integer representing total repeat times of string T_i by repeaters from l to r ( not l' to r' ).
示例1

输入

复制
3
gugugu
gugugu
guguguuuuuuu
2
1 2 gu
7 5 guu

输出

复制
6
1