#SL2310J. Border Queries
Border Queries
Border Queries
Given a string of length consisting of lowercase English letters. A partition of into three non-empty substrings is considered good if and only if is the border of and is the border of . We say a string good if and only if is a substring of and there exists a good partition of into such that .
Define the value of a string as the number of its good substrings. Two substrings are considered different if and only if the start position is different or the end position is different.
Given a string of length consisting of lowercase English letters and queries. In each query, you are given two integers . You need to calculate the value of .
Input
Each test contains multiple test cases. The first line contains an integer denoting the number of test cases.
For each test case, the first line contains three integers $n,m,q \: (3 \leq n \leq 10^6, 1 \leq m,q \leq 10^6)$.
The second line contains a string of length .
The third line contains a string of length .
The next lines each contains two integers and , denoting a query .
It is guaranteed that over all test cases does not exceed .
Output
For each query, output one line with an integer denoting the answer.
Please do not output trailing spaces.
Example
1
7 7 2
abacaba
cabacab
1 4
3 7
0
2