#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <complex>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <deque>
#include <bitset>
#include <cctype>
#include <utility>
#include <cassert>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
int a[8011];
long long f[11][66];
int main() {
ios :: sync_with_stdio(false); cin.tie(NULL);
cout << (fixed) << setprecision(6);
int test; cin >> test;
while (test--) {
int m, n, q; cin >> m >> n >> q;
FOR(i,1,m) {
string s; cin >> s;
a[i] = s.length();
}
memset(f, 0, sizeof f);
f[0][0] = 1;
FOR(i,0,n-1)
FOR(l,0,50)
if (f[i][l] >= 0) {
FOR(add,1,m)
f[i+1][l + a[add]] += f[i][l];
}
while (q--) {
int x; cin >> x;
cout << f[n][x] << endl;
}
}
return 0;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgoja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GVzdDsgY2luID4+IHRlc3Q7CiAgICB3aGlsZSAodGVzdC0tKSB7CiAgICAgICAgaW50IG0sIG4sIHE7IGNpbiA+PiBtID4+IG4gPj4gcTsKICAgICAgICBGT1IoaSwxLG0pIHsKICAgICAgICAgICAgc3RyaW5nIHM7IGNpbiA+PiBzOwogICAgICAgICAgICBhW2ldID0gcy5sZW5ndGgoKTsKICAgICAgICB9CgogICAgICAgIG1lbXNldChmLCAwLCBzaXplb2YgZik7CiAgICAgICAgZlswXVswXSA9IDE7CiAgICAgICAgRk9SKGksMCxuLTEpCiAgICAgICAgICAgIEZPUihsLDAsNTApCiAgICAgICAgICAgIGlmIChmW2ldW2xdID49IDApIHsKICAgICAgICAgICAgICAgIEZPUihhZGQsMSxtKQogICAgICAgICAgICAgICAgICAgIGZbaSsxXVtsICsgYVthZGRdXSArPSBmW2ldW2xdOwogICAgICAgICAgICB9CgogICAgICAgIHdoaWxlIChxLS0pIHsKICAgICAgICAgICAgaW50IHg7IGNpbiA+PiB4OwogICAgICAgICAgICBjb3V0IDw8IGZbbl1beF0gPDwgZW5kbDsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQoK