2346: make word

内存限制:128 MB 时间限制:2.000 S
评测方式:文本比较 命题人:
提交:37 解决:5

题目描述

    Probably, you have seen polyhedrons which have an English letter on each face of them. Little Ali has some of these polyhedrons and some words in his mind. We want to know how many of these words can be made by juxtaposing these polyhedrons. For instance, suppose that little Ali has one tetrahedron that letters B,Z,G,K are printed on its faces and one cube  which letters  O,O,O,O,O,O are printed on its faces. With this two polyhedrons little Ali can make “OK” and “GO”.

输入

    First line of Input contains number of the tests.

    For each test case, first you are given an integer n , the number of polyhedrons and m, then number of words that  little Ali has. You can assume that 1<=n,m<=300. Then there are n string such that string i shows the letters which are printed on the faces of polyhedron  i. After that you are given  m words.

输出

    For each test case, print number of words that little Ali can make by juxtaposing his polyhedral.

样例输入 复制

1
4  3
AAAA BBBB CCCCCC   DD
BAD DAD  DAB 

样例输出 复制

2

来源/分类