Problem: You are given a string , consisting of lowercase Latin letters.
You are asked queries about it: given another string , consisting of lowercase Latin letters, perform the following steps:
- concatenate and ;
- calculate the prefix function of the resulting string ;
- print the values of the prefix function on positions ( and denote the lengths of strings and , respectively);
- revert the string back to .
The prefix function of a string is a sequence , where is the maximum value of such that and ( denotes a contiguous substring of a string from a position to a position , inclusive). In other words, it's the longest proper prefix of the string that is equal to its suffix of the same length.
Input Format: The first line contains a non-empty string (), consisting of lowercase Latin letters.
The second line contains a single integer () — the number of queries.
Each of the next lines contains a query: a non-empty string (), consisting of lowercase Latin letters.
Output Format: For each query, print the values of the prefix function of a string on positions .