According to Wikipedia: An anagram is a word or phrase formed by rearranging the letters of a different word or phrase. For example: “evil” and “vile” are anagram of each other, "silent” and “listen” are anagram of each other. Accordingly, all the anagrams for the string “aba” are: “aba”, “aab”, “baa”.
You will be given a dictionary of N words. You need to answer Q queries. In each query, you will be given a string. You need to answer how many words are there in the dictionary whose at least one anagram is present as a subsequence in the query string.
Input
The first line of the input contains a single integer T (1 ≤ T ≤ 100) which denotes the number of test cases. First line of each test case has an integer N (2 ≤ N ≤ 100) denoting the number of words in the dictionary. Each of the next N lines contains one string.
Next line contains an integer Q (1 ≤ Q ≤ 100), the number of queries. Each of the next Q lines contains one string. All the strings in the input will contain only lowercase letters and the length of any string will not exceed 100.
Output
The first line of each output should contain the test care number in the format “Case X:” where X is the test case number. Each of the next Q lines should contain one number, the output for the associated query. Please see the sample input output for more clarification.
Sample
Sample Input | Sample Output |
---|---|
1 3 ncpc code champion 2 decon hypomaniced | Case 1: 1 2 |
Notes
Contest: NCPC 2023 Onsite Hosted by JU
Problem setter: Raihat Zaman Neloy