#K72572. Counting Substring Occurrences

    ID: 33783 Type: Default 1000ms 256MiB

Counting Substring Occurrences

Counting Substring Occurrences

Given a collection of strings and several query substrings, your task is to count how many times each query appears as a substring in the collection. Each query should be matched in a non-overlapping manner (similar to the behavior of many built-in functions).

For each test case, you will be provided with an integer n (the number of strings), followed by n lines each containing a string. Then an integer m (the number of queries) is provided, followed by m lines each containing a query substring. Your goal is to output, for each test case, a single line with m space-separated integers representing the count of each query found in the given strings.

inputFormat

The input is read from stdin and formatted as follows:

  1. The first line contains an integer T indicating the number of test cases.
  2. For each test case:
    1. The first line contains an integer n — the number of strings.
    2. The next n lines each contain a string.
    3. The following line contains an integer m — the number of query substrings.
    4. The next m lines each contain a query substring.

outputFormat

For each test case, output a single line with m space-separated integers. The i-th integer represents the total count of occurrences of the i-th query substring within all the given strings. The output is written to stdout.

## sample
3
1
hello
4
he
lo
o
world
2
hello
world
5
lo
or
he
wo
l
3
test
testing
tested
3
test
testing
tested
1 1 1 0

1 1 1 1 3 3 1 1

</p>