Limits 1s, 512 MB

Who doesn't love food? Especially if someone is giving a treat! Thats right! Redoan is a treat hunter. Whenever he gets a chance to snatch a treat from anyone, he does not miss the chance. A lot of kind hearted, innocent brothers have fallen victim to his hunting. The next one is Shagor. Who is Shagor? Thats a long story. We will listen to his story on our next contest. Right now Redoan is worried about his hunting. He has asked assistance from three other treat hunters Swapnil, Shibli and Pizon.
But Shibli refuses to go as he is really very sad after missing 0.5 marks in a class exam!! After getting requested a lot, Shibli agrees to go with them on one condition. Redoan has to solve one problem.
Shibli will give Redoan N strings. After that he will give Redoan M strings. For each of the M strings Redoan has to find out number of strings in the first list that are not any of the permutations of it.
Now Redoan needs help. As time and treat waits for none. He promises that if anyone can solve this problem for him he will give a treat to that person.

Input

First line contains a number T.
T test cases follow. Each case contains N and M. After that N strings are given. Then M queries follow. For each query you will get one string S.

Here,
T ≤ 10,
1 ≤ N,M ≤ 105 ,
1 ≤ length of S ≤ 10
S will contain only lowercase alphabets.

Output

Print "Case no:" at first for each test case. And then each of the M lines will contain the desired number. See sample I/O for better understanding.

Sample

InputOutput
1
3 2
abc
cba
bac
acb
xyz
Case 1:
0
3

Submit

Login to submit.

Statistics

70% Solution Ratio
RenegadesEarliest, Jan '18
Kuddus.6068Fastest, 0.4s
alamkhanLightest, 14 MB
sarwarITShortest, 747B
Toph uses cookies. By continuing you agree to our Cookie Policy.