The Ninjanet of Ninjaland has N websites. The name of all websites is in the form of a string and all of them have a length equal to M. Ayush is searching for his favourite website but unfortunately, he forgot some of the characters of the website so he replaced those characters with ‘?’. Your task is to calculate the number of websites that can possibly be a favourite of Ayush.
For example:There are three websites in Ninjanet that are: "abc", "aba" and "aac".
If Ayush searches for “ab?” then there will be 2 websites that could be a favourite of Ayush, which are "abc" and "aba".
If Ayush searches for “?a?” then there will be only 1 website that could be a favourite of Ayush, i.e. "aac".
The first line of input contains three space-separated integers N, M and Q, denoting the number of websites, length of each website and number of queries respectively.
Next, the N line contains a single string, where the ith line consists of the name of the ith website in the Ninjanet.
Next, the Q line contains a query string, the name of the favourite website of Ayush with certain ‘?’ characters (Possibly 0), as described in the problem statement.
Output format :
For each query, print a single integer on a newline, denoting the number of websites that can possibly be Ayush’s favourite website.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraint :
1 <= N <= 10^4
1 <= M <= 6
1 <= Q <= 10^5
Time Limit: 1 sec
5 3 5
cat
map
cam
eat
fat
?at
ca?
?a?
??t
???
3
2
5
3
5
For the first query, there are 3 possible favourite websites that are “cat” , “eat” and “fat”.
For the second query , there are 2 possible favourite websites that are “cat” , “cam”.
For the third query , all the websites have ‘a’ at their 2nd place so all are possible favourites.
For the fourth query , there are 3 possible favorite websites that are “cat” , “eat” and “fat”.
For the fifth query , all the websites can be possible favourites.
3 3 2
abc
aac
aba
ab?
?a?
2
1
Try to compare query with every website
O(N * M * Q), where N is the number of websites, M is the size of each website and Q is the number of queries.
Because we are matching the query with N websites of length M and there are Q such queries.
O(1)
As we are using constant extra space.