socialhare

Little Elisa is learning her first words. With the help of her parents and friends, she has been introduced to word search puzzles in order to practice and acquire new vocabulary. A search word puzzle consists of a rectangular arrangement of lowercase English characters and a list of words (each consisting of lowercase English characters too), with the goal of finding as many words from the list as possible in the arrangement of letters. However, little Elisa thinks of word search puzzles in a more relaxed way: she considers a word w to occur in a rectangular arrangement of letters if she can find any permutation of w in the rectangular arrangement (horizontal, vertical or diagonally). Since little Elisa is a bit of an anarchist and “women always get the last word in every argument”, her parents and friends have designed some word search puzzles so that Elisa can have fun her own way. They are asking for help in checking if Elisa’s solutions are correct. Can you help? Input The input consists of several test cases. The first line of a test case contains three-blank separated integers R, C, W (1 ≤ R, C, W ≤ 100) denoting the number of rows R and columns C of the rectangular arrangement of characters, and the number of words W to search for in the game. Each of the following R lines consists of exactly C lowercase English characters. Then, the next W lines describe the list of words to search for in the arrangement of characters. Each of these lines contains a non-empty sequence of at most 100 lowercase English characters. Output For each test case, output the maximum number of words from the given list of W words that appear, according to Elisa’s rules, in the rectangular arrangement of R × C-characters. Sample Input 10 11 3 entanglerci alkaksckasj qwicasasqwb asososqweqn gasxahqaqsa psposrtgppa uuusasosaah zxcvbnmclwq xscdvfbghqr fsdddllslaq socialhare rectangle bear 226 ab cd ba

2/2 ac aa da cb ae Sample Output 1 4