Substring search

You are given a string ss and many short patterns, all of the same length. The string ss 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 ss. Can you do it efficiently, both in time and in space?

Input

Input starts with a number tt, followed by tt cases. Each case begins with a non-empty string ss, followed by a number p1p \ge 1, followed by pp non-empty patterns. The only characters in ss and in the patterns are ‘a’ and ‘b’. The length of ss is at most 10610^6. All the patterns of the same case have the same length, which is at most 60. No given pattern is longer than ss.

Output

For every case, print the case number starting at 1 followed by the number of times that each given pattern is included in ss. Print a blank line after every case.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:02:31.417Z

© Jutge.org, 2006–2026.
https://jutge.org