In this problem, you are asked to implement a more efficient string matching method, called "rolling hash". In this method, strings are first mapped to integer hash values. Then, when two strings can be mapped to the same hash value, the two strings are said to be "matched".
The "rolling hash" maps a given string to an integer using the following function:
,
where a=9487 is a constant and c1, c2, ..., ck are the chars of the given string.
Note that, the H hash value can be very large, so please use long long int type and module it by M=99999989 (the largest 8-digit prime number) in each add or multiply operation.
For example:
H("abc")=((((9487*9487)%M*'a')%M+(9487*'b')%M)%M+'c')%M=31238175
H("123")=((((9487*9487)%M*'1')%M+(9487*'2')%M)%M+'3')%M=10630166
Thus, "abc" is mapped to 31238175, while "123" to 10630166.
(It is guaranteed that in the test cases, no two different strings will be mapped to the same hash value if you follow the suggested hash function implementation.)
For complete problem description, please refer to 13277.
The first line contains 2 integers n and m, which are the sizes of S1 and S2, respectively. (0 < n,m <= 1000)
Next, there're n lines, each representing a string in S1.
Last, m lines are provided, each representing a string in S2.
The lengths of the strings are not greater than 5*10^4.
Print m lines. Each line contains "Yes" or "No", which means whether the i-th string in S2 exists in S1 or not.
Print '\n' at the end of each line.