Archive Shadows
Two curators compare two strings: a draft strip and an old archive . A fragment of is chosen by two positions and with ; its text is .
A fragment is called shadowed if the same text occurs as a contiguous substring of . Otherwise, it is called fresh.
You are given inspection ranges. For each range , count the number of pairs such that and the fragment is fresh.
Input
The first line contains a string (). The second line contains a string (). Both strings consist only of lowercase English letters. The third line contains an integer (), the number of inspection ranges. The next lines contain descriptions of the ranges. In the -th of these lines, there are integers and ().
Output
For each inspection range, print one integer: the number of fresh fragments fully contained in that range. The answers must be printed in the same order as the input ranges.
Samples
Sample 1
Input
ababa bab 3 1 5 1 3 2 4
Output
5 1 0
For , the fresh intervals are , , , , and . For , only is fresh. For , every fragment is shadowed.