


The name of the file should be greater than or equal to the string ‘A’.
The name of the file should be less than or equal to string ‘B’.
The name of the file should not contain the virus string as a substring ‘C’.
Since the answer can be very large, print answer % (10^9 + 7).
If N=2 and string ‘A’ = “bc” and string ‘B’ = “bm” and virus string ‘C’ = ”g”.So the files that are not affected are “bc”, “bd”, “be”, “bf”, “bh”, “bi”, “bj”, “bk”, “bl”.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N’, denoting the length of the file’s name.
The second line contains three strings corresponding to ‘A’, ’B’ and ‘C’.
For each test case, print an integer corresponding to the number of unaffected files % (10^9 +7).
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 500.
length of ‘A’ and ‘B’ == N.
1 <= length of string ‘C’ <= N .
Time limit: 1 sec
In this approach, we will declare a recursive function HELPER(‘CUR’,’ TARGET’,’ VIRUS’) that returns the number of unaffected files having a name lexicographically less than or equal to ‘TARGET’.
HELPER() function will create all possible strings and check if it’s affected or not.
We will first call HELPER() function as ‘TARGET’ as ‘B’ and store it in ‘ANS’.
Then we will update ‘ANS’ as ‘ANS’ - HELPER(“”,’ A’, ’C’).
At last, we will check if ‘A’ is affected or not and increment ‘ANS’ by 1 accordingly.
In this approach, we will declare a recursive function HELPER(‘i’,’j’, TARGET’, ’VIRUS’,’ TIGHT’) that will return the number of non - affected files having names less than or equal to ‘TARGET’.i is the index corresponding to current filename string,j is the index corresponding to ‘VIRUS’ string and ‘TIGHT’ is a boolean parameter that will decide either we can add character till ‘z’ or till target[i].We will try to letter to the current filename and if the i is equal to length of ‘TARGET’ we will return 1 as we formed an unaffected filename. We will also use a ‘DP’ table to memoize this solution.