Word Problem 

In a popular puzzle often found in newspapers, a set of letters is provided, and the challenge is to find how many different words can be made from these letters. This problem is designed to take all the fun out of it by automating the process.


Input will be in two parts. The first part will be a dictionary of less than 1000 lines, containing words to be searched for. Each line will contain one word of up to 10 characters. Each word will be in lower case. The words will be in alphabetical order. The end of the dictionary will be indicated by a line consisting of a single `#' character.

After the dictionary there will be data for several word puzzles, each on a separate line. Each puzzle line will have from one to 7 lower case letters, separated by one or more spaces. Your task is to arrange some or all of these letters to form words in the dictionary. The list of puzzles will be terminated by a line consisting of a single `#'.


For each puzzle line in the input, a single line of output should be produced, containing the number of different words in the dictionary that can be formed using the letters in the puzzle line.

Note that each letter may be used only as many times as it appears in the puzzle line. For instance, the puzzle line `u l l' may produce the word `lul' but not the word `lull'.

Sample Input 

b e w
b b e e w w
t a n c u g d

Sample Output 


Miguel Revilla 2004-07-08