Codejamon Cipher (Small)

For each enciphered string, count the sentences of vocabulary words whose letter multisets concatenate to it, modulo 1e9+7.

Medium5Dynamic programmingHash mapCombinatoricsNo attempts yetTime limit5sMemory limit512 MB

Problem

Codejamon monsters talk in enciphered strings. Each kind of monster has its own vocabulary, a list of VV different words made of lowercase English letters.

When a monster speaks, it first builds a sentence out of words from its vocabulary. The same word may appear several times in one sentence. It then turns the sentence into an enciphered string in two steps.

  1. Shuffle the letters of each word at random.
  2. Remove all spaces.

Given an enciphered string, count how many original sentences could have produced it. Two sentences differ when their sequences of words differ, and two vocabulary words that become equal after shuffling still count as different words. For example, with the vocabulary ["this", "is", "a", "dog", "god"], the enciphered string ishtsiaogd comes from four sentences.

  • is this a dog
  • is this a god
  • this is a dog
  • this is a god

You have SS enciphered strings from the same monster. For each one, report the number of possible original sentences. The answer can be very large, so print it modulo the prime 109+710^9 + 7.

Input

The first line contains the number of test cases TT.

The first line of each test case contains two integers VV and SS, the size of the vocabulary and the number of enciphered strings. The next VV lines each contain one word of the vocabulary. Every word consists of lowercase English letters, and the words are different from each other. The next SS lines each contain one enciphered string, also made of lowercase English letters.

Every enciphered string is valid: at least one original sentence produces it.

Output

For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the list of the SS answers separated by single spaces, in the order the strings were given. Each answer is taken modulo 109+710^9 + 7.

Constraints

  • 1T1001 \le T \le 100
  • 5V105 \le V \le 10
  • 1S51 \le S \le 5
  • Each word of a vocabulary has length between 1 and 5.
  • Each enciphered string has length between 1 and 50.