This page is still under construction.

Parts of this page are still being built. What you see may change.

Dice Password Security

Time limit1sMemory limit1024 MB

Summary
Given a dictionary of words with no word a substring of another, count how many n-word concatenations have each queried total length.
Level

Hard8 of 10

Topics
Dynamic programming, String matching, Trie, Combinatorics
Solved
No attempts yet

Problem

The NCIM Group does a lot of work on IT solutions in defense and security. Good security usually starts with picking a strong password. Generating a password at random is generally a good practice. For example, a password like "2R4eZ9Rqup" is a bit harder to guess than "god", "love", "sex" or "secret".

The problem with passwords consisting of random letters and digits is that they are hard to remember. Instead of using letters and digits, it is also possible to generate passwords by putting random words together. Words are easier to remember than letters and digits. Using a dictionary of 7776 (656^5) words, a 5-random-word password is about as strong as a 11-random-character password.

77765=28430288029929701376≈3⋅10197776^5 = 28430288029929701376 \approx 3 \cdot 10^{19}

6211=52036560683837093888≈5⋅101962^{11} = 52036560683837093888 \approx 5 \cdot 10^{19}

Some applications hide the password you are typing on the screen by printing dots or asterisks. This allows someone watching your screen to count the number of characters in your password. The NCIM Group wants you to find out whether or not this compromises the strength of your password.

You must write a program that calculates the number of possible passwords that can be generated given:

  • the dictionary of words,
  • the amount of words used to generate the password and
  • the length of the password.

Input

On the first line an integer tt (1≤t≤1001 \le t \le 100): the number of test cases. Then for each test case:

  • One line with three positive integers mm (1≤m≤77761 \le m \le 7776), nn (1≤n≤51 \le n \le 5) and qq (1≤q≤201 \le q \le 20): the number of words in the dictionary, the number of words to generate the password, and the number of queries, respectively.
  • The dictionary: mm lines each containing one word wiw_i. Each word consists only of lowercase letters. The length of each word will be between 3 and 10 inclusive. No word in the dictionary will be a substring of another word in the dictionary.
  • qq lines each containing a positive integer ljl_j (1≤lj≤501 \le l_j \le 50), the length observed.

Output

For each test case:

  • qq lines with: the number of possible passwords with length ljl_j. This number will be smaller than 2632^{63}.

Examples1

  1. Example 1

    Input
    1
    4 2 2
    aap
    noot
    mies
    piet
    7
    8
    
    Expected output
    6
    9