Program Security;
Const
    MinWordLength       =    3;
    MaxWordLength       =   50;
    MaxPasswordWords    =    5;
    MaxPasswordLength   = 1000;
Var
    Cases           : Integer;
    Queries         : Integer;
    TotalWords      : Integer;  (* Total number of words in the dictionary *)
    NumWords        : Integer;  (* Number of words in the password *)
    Count           : Array[MinWordLength..MaxWordLength] of Integer;
    Combis          : Array[0..MaxPasswordWords] of
                      Array[0..MaxPasswordLength] of Int64;
    Word            : String;
    c, q, i, j, k   : Integer;

Begin
    ReadLn(Cases);
    For c := 1 to Cases do
    Begin
        ReadLn(TotalWords, NumWords, Queries);

        (* Read dictionary words and count their lengths *)
        For k := MinWordLength to MaxWordLength do
            Count[k] := 0;
        For i := 1 to TotalWords do
        Begin
            ReadLn(Word);
            Inc(Count[Length(Word)]);
        End;

        (* Calculate number of combinations *)
        For i := 0 to MaxPasswordWords do
            For j := 0 to MaxPasswordLength do
                Combis[i][j] := 0;
        Combis[0][0] := 1;
        For i := 1 to MaxPasswordWords do
            For j := 1 to MaxPasswordLength do
                For k := MinWordLength to MaxWordLength do
                    If (k <= j) and (Combis[i - 1][j - k] > 0) then
                            Combis[i][j] := Combis[i][j] + Count[k]*Combis[i - 1][j - k];

        (* Read and answer queries *)
        For q := 1 to Queries do
        Begin
            ReadLn(k);
            WriteLn(Combis[NumWords][k]);
        End
    End
End.
