You are given a string
and many short patterns, all of the same length. The string
and the patterns are composed only of ‘a’ and
‘b’ characters. For every given pattern, you must tell how
many times it is included in
.
Can you do it efficiently, both in time and in space?
Input starts with a number
,
followed by
cases. Each case begins with a non-empty
string ,
followed by a number
,
followed by
non-empty patterns. The only characters in
and in the patterns are ‘a’ and ‘b’. The
length of
is at most
.
All the patterns of the same case have the same length, which is at most
60. No given pattern is longer than
.
For every case, print the case number starting at 1 followed by the number of times that each given pattern is included in . Print a blank line after every case.
Input
2 aabaaaabaaab 3 aaba aaaa baab bbbbbbbb 1 bb
Output
Case 1: 2 1 0 Case 2: 7