문제
A program consists of a sequence of instructions, each of which is of one of the following forms:
, where is a digit in the range [0,9]$$+s, where is a string denoting the name of a variable. Within a program, all variable names must be distinct.
The result of executing a program is defined to be the expression that results after applying each instruction in order, starting with . For example, the result of executing the program is the expression . Different programs, when executed may produce the same expressions; for example, executing would also result in the expression .
Bessie and Elsie each have programs of () instructions. They will interleave these programs to produce a new program of length . Note that there are ways to do this, but not all such programs, when executed, will produce distinct expressions.
Count the number of distinct expressions that may be produced by executing Bessie and Elsie's interleaved program, modulo .
Each input contains () test cases that should be solved independently. It is guaranteed that the sum of over all test cases does not exceed .
입력
The first line of the input contains , the number of test cases.
The first line of each test case contains .
The second line of each test case contains Bessie's program, represented by a string of length . Each character is either a digit , representing an instruction of type 1, or the character , representing an instruction of type 2.
The third line of each test case contains Elsie's program in the same format as Bessie's.
Within a test case, the variable names among all instructions are distinct. Note that their actual names are not provided, as they do not affect the answer.
출력
The number of distinct expressions that may be produced by executing Bessie and Elsie's interleaved programs, modulo .
예제 입력 1
4
1
0
1
3
12+
+02
3
0++
++9
4
5+++
+6+1
예제 출력 1
1
3
9
9
점수
Input 2 satisfies .In inputs 3-5, the sum of all is at most .In inputs 6-8, the sum of all is at most .Inputs 9-16 satisfy no additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인