Hongjun Likes Strings

For each of up to 100000 queries, find the shortest substring of a fixed string S that contains both given short patterns A and B, allowing overlap.

Hard8StringString matchingPrefix sumBinary searchNo attempts yetTime limit2sMemory limit512 MB

Problem

Hongjun likes strings, so he keeps making up problems about them.

Here is one of them. Given a string SS and two strings AA and BB, find the shortest contiguous substring of SS that contains both AA and BB as substrings. The occurrence of AA and the occurrence of BB are allowed to overlap.

Hongjun is smart, so he solved that at once. Then he thought of a harder version, in which the two strings AA and BB arrive as QQ separate questions. He could not find a fast way to answer them, so he decided that short AA and BB would let him solve it quickly.

Help Hongjun and write a program that answers every question.

Input

The first line contains a string SS of length at most 5000050\,000.

The second line contains the number of questions QQ, an integer with 0Q1000000 \le Q \le 100\,000.

Each of the next QQ lines contains two strings AA and BB separated by a space. The length of AA and the length of BB are between 11 and 44.

SS, AA, and BB consist of lowercase English letters only.

Output

Print the answers to the QQ questions, one per line. On each line print the minimum length of a contiguous substring of SS that contains both AA and BB as substrings. If no such contiguous substring exists, print 1-1.