Trie Sharding

Split the strings among N labeled non-empty servers to maximize the total trie node count and report the maximum and the count of optimal splits modulo 1e9+7.

Hard8Dynamic programmingTrieCombinatoricsNo attempts yetTime limit5sMemory limit512 MB

Problem

A set of strings SS can be stored compactly in a trie. A trie is a rooted tree that has exactly one node for every distinct prefix of the strings in SS, counting the empty prefix.

For example, if SS is "AAA", "AAB", "AB", "B", the trie has 7 nodes, one for each of the prefixes "", "A", "AA", "AAA", "AAB", "AB", "B".

One server holds all of SS in a single trie. SS has grown too large to fit in that server's memory, so SS is spread over NN servers instead. SS is split into disjoint non-empty subsets T1,T2,,TNT_1, T_2, \dots, T_N, and server ii builds a trie that holds only the strings in TiT_i. The total number of nodes over all NN tries can then be larger than the number of nodes in the single trie, and the way the strings are split cannot be controlled.

Take the same four strings and split them over two servers, "AAA" and "B" on the first server, "AAB" and "AB" on the second. The first trie needs 5 nodes ("", "A", "AA", "AAA", "B") and the second trie also needs 5 nodes ("", "A", "AA", "AAB", "AB"). The two servers hold 10 nodes together, against the 7 nodes one server needs for all four strings.

Given SS and NN, find the largest total number of nodes that a split can produce, and count the splits that reach it. The servers are distinguishable: if a string lies in TiT_i in one split and in TjT_j with iji \ne j in another split, the two splits are different. Report the count modulo 1,000,000,007.

Input

The first line has the number of test cases TT. Each test case starts with a line holding two integers MM and NN separated by a space. The next MM lines each hold one string of SS.

Limits

  • 1T1001 \le T \le 100
  • 1M10001 \le M \le 1000
  • 1N1001 \le N \le 100
  • NMN \le M
  • Every string of SS has 1 to 100 characters and uses upper case English letters only.
  • The strings of SS are all distinct.

Output

For each test case print one line in the form "Case #i: X Y", where ii is the test case number starting from 1, XX is the largest total number of nodes over all NN tries, and YY is the number of splits whose total node count is XX, taken modulo 1,000,000,007.