You are given a string of lowercase letters and let
be the number of occurrences of
in
, we define an encryption function
as follows:
where '' means string concatenation, for example,
.
For each query string , please calculate
.
The first line contains a string
of lowercase letters.
The second line contains an integer![]()
indicating the number of queries.
For the nextlines, each line contains a nonempty lowercase query string
.
It is guaranteed that the sum of the length of all queries doesn't exceed.
For each query, output the encrypted result in a single line.