Reducto
The National Security Agency of ByteLand has decided to clamp down on free and unrestricted media. They have decided to form a new language - Reducto, which removes all occurrences of some specified words from any string. Note that the words are to be removed iteratively i.e.the new string resulting from the removal of a word from a string may have newer occurrences of restricted words.(For more details see Sample Input and Output).
Your job is to write a program doing the reduction on a string for them. You have to minimise the length of the resulting string.
Input:
The first line contains the number of test cases T.T lines follow each with a test case.
Each Test case begins with the integer N followed by the string S to be reduced, followed by N strings, each representing a restricted word.
Output:
For each test case output the length of the final resulting string.
Constraints:
1<=T<=150
1<=N<=50
Length of S is atmost 50 characters
Sample Input:
3
2 acmmcacamapapc mca pa
1 ccdedefcde cde
2 aabaab aa bb
Sample Output:
6
1
0
Possible reductions for the sample inputs are:
acmmcacamapapc-> acmcamapapc -> acmapapc -> acmapc
ccdedefcde -> cdefcde -> fcde -> f
aabaab -> aabb -> aa -> 'Empty String'