#include <cstdio>
#include <cstring>

int main() {

	int t; scanf("%d", &t);

	while( t-- ) {

		int n, m, q; scanf("%d%d%d", &n, &m, &q);
		int dict[11]; memset(dict, 0, sizeof(dict));

		for( int i = 0; i < n; ++i ) {
			char buf[11]; scanf("%s", buf);
			++dict[strlen(buf)];
		}

		long long ans[11][101]; memset(ans, 0, sizeof(ans));

		ans[0][0] = 1;

		for( int w = 0; w < 10; ++w ) {

			for( int len = 0; len <= 90; ++len ) {

				for( int add = 1; add <= 10; ++add ) {

					ans[w+1][len+add] += dict[add] * ans[w][len];
				}
			}
		}

		while( q-- ) {

			int x; scanf("%d", &x);

			printf("%lld\n", ans[m][x]);
		}
	}

	return 0;
}

