Some days ago, WJMZBMR learned how to answer the query "how many times does a string *x* occur in a string *s*" quickly by preprocessing the string *s*. But now he wants to make it harder.

So he wants to ask "how many consecutive substrings of *s* are cyclical isomorphic to a given string *x*". You are given string *s* and *n* strings *x*<sub class="lower-index">*i*</sub>, for each string *x*<sub class="lower-index">*i*</sub> find, how many consecutive substrings of *s* are cyclical isomorphic to *x*<sub class="lower-index">*i*</sub>.

Two strings are called cyclical isomorphic if one can rotate one string to get the other one. 'Rotate' here means 'to take some consecutive chars (maybe none) from the beginning of a string and put them back at the end of the string in the same order'. For example, string "abcde" can be rotated to string "deabc". We can take characters "abc" from the beginning and put them at the end of "de".
The first line contains a non-empty string *s*. The length of string *s* is not greater than 10<sup class="upper-index">6</sup> characters.

The second line contains an integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — the number of queries. Then *n* lines follow: the *i*-th line contains the string *x*<sub class="lower-index">*i*</sub> — the string for the *i*-th query. The total length of *x*<sub class="lower-index">*i*</sub> is less than or equal to 10<sup class="upper-index">6</sup> characters.

In this problem, strings only consist of lowercase English letters.
from collections import deque,OrderedDict
s = input()
d = {}
for i in range(len(s)):
    for j in range(i,len(s)):
        d[s[i:j+1]] = d.get(s[i:j+1],0) + 1
n = int(input())
print(d)
for i in range(n):
    count = 0
    t = {}
    s = deque(input())
    #count += d.get(''.join(s),0)
    t[''.join(s)] = ''.join(s)
    for i in range(len(s)):
        s.rotate(1)
        #count += d.get(''.join(s),0)
        t[''.join(s)] = ''.join(s)
    for i in t:
        count += d.get(i, 0)

    print(count)

