#P9908. Border Queries
Border Queries
Border Queries
Problem Description
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 (, ). 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.
Sample Input
1
7 7 2
abacaba
cabacab
1 4
3 7
Sample Output
0
2
Source
2023“钉耙编程”中国大学生算法设计超级联赛(10)