Tobby and the quaseEquals strings

Tobby always enjoys playing with strings, and now he brings to you a nice problem with them. Of course, since Tobby is a lazy dog, he has not solved it yet and hopes that you can solve it for him. Tobby got a set of strings S of size N (where every string has the same length L). He also has Q queries. For each query a string A of size L is given and Tobby wants to know how many strings in S are quaseEquals to A for every i (1 ≤ i ≤ L). Two strings are quaseEquals to one another for an index i if they are equal after deleting the i-th character from both strings. Input The input consists of several test cases, read until the end of file (EOF). In the first line of each test case there are three integers: N, Q, L (1 ≤ N,Q,L ≤ 105). The next N lines contain the strings in S, all of length L. Finally Q strings of length L are given, those are the queries. It is guaranteed that (1 ≤ N∗L ≤ 100000) and (1 ≤ Q∗L ≤ 100000) and that all strings in the input contain only english lowercase letters (a..z). Output For each query print the number of strings in S that are quaseEquals to the string in the query for every position 1 ≤ i ≤ L. Explanation: For the first sample, if the character i = 1 is removed, then S = {ab, ba, aa} and A = {aa} and we got 1 pair of quaseEquals strings. If the character i = 2 is removed, then S = {ab, aa, aa} and A = {aa} and we got 2 pairs of quaseEquals strings. If the character i = 3 is removed, then S = {aa, ab, aa} and A = {aa} and we got 2 pairs of quaseEquals strings, so our answer is 1 + 2 + 2 = 5. Sample Input 313 aab aba aaa aaa Sample Output 5