Medium Math > Counting

We know that MR. Royel is the oldest man and his family is the biggest family in the world. So, he faces a problem to find names for new family member. Thats why he comes to you, and you have to help him. You are given the length of names **L** and a collection of strings **S**. You have to find the number of distinct names which have any string from collection **S** as a suffix. Input: -- Input start with test cases **T**. Each test case first line contains two integer **L** , length of names and **N**, the number of string in collection **S**. Next line contains **N** strings, the collection of strings **S**. Name and strings will contain only lowercase letter **‘a’-’z**’. Constrains: -- 1<=T<=100 1<=L<=100 1<=(|S1|+...+|SN|)<=100 Where |S1| denote the length of string S1 and so on. Output: -- For each case input, output a single line printing the total number of distinct names.<br> Note: The answer may be very large. Use appropriate data type. Sample Input: -- 2 2 2 aa b 3 4 ab bc cd abd Sample Output -- 27 79

Monikrishna Roy