Under construction

Still being built. Things may change

A Text Problem

Time limit6sMemory limit512 MB

Summary
For each query string, count the positions in T where it occurs with at most one mismatched letter.
Level

Hard8 of 10

Topics
String matching, Hash map, String
Solved
No attempts yet

Problem

The string AA occurs in the string BB at position ii with at most one mistake if and only if either AA occurs in BB at position ii, or there exists a string A′A' obtained from AA by replacing the letter at a single position with a different letter such that A′A' occurs in BB at position ii.

You are given a string TT and a series of queries. Each query is a string for which you should compute the number of positions at which it occurs in TT with at most one mistake.

Input

The first line of input contains the number of test cases zz. The descriptions of the test cases follow.

The first line of each test case contains a string of length between 11 and 200,000200\\,000 consisting of lowercase Latin letters: the string TT. The next line contains one integer qq: the number of queries. Each of the following qq lines contains a nonempty string consisting of lowercase Latin letters: a query. The sum of lengths of all queries in a test case is at most 200,000200\\,000.

The sum of lengths of all strings appearing in all test cases (including queries) does not exceed 1,200,0001\\,200\\,000.

Output

For each query, output the number of positions in TT at which the query occurs with at most one mistake.

Examples1

  1. Example 1

    Input
    1
    abcdefghij
    2
    abd
    a
    
    Expected output
    1
    10