Ms.Shivani has given an assignment to her students. The students are given long words. They have to find out the maximum number of words a given word can be split into, such that the resulting words all form legitimate words contained in a given dictionary. The broken up words must be continuous in the parent word. See example for clarification.
For example, the string AMANGO can be split as {A, MANGO}, {A, MAN, GO} and {AM, AN, GO}, wherein, each of the resulting words is contained within the dictionary {A, AM, AN, GO, MAN}, here the final set of split up words does not produce any word that is not contained in the dictionary.The students are having a tough time completing this assignment. They cannot even copy it as not a single person has been able to do it. Help them out.
INPUT: First line contains the number of test cases to follow, 1<=t<=10, Next line contains the String, n that has to be divided into words. The size of the string is between [1,1500], both inclusive. Next line contains, l the number of words in the dictionary, 1<=l<=100 Next l line contains l words.
Note: There is one line gap between two test cases.
OUTPUT: For each test case output the maximum number of words that can be generated from the string.
For case 1: the split for this string is: a, man, ten, ton, one, wit, heel.