#P8256. [NOI Online 2022 入门组] 字符串

[NOI Online 2022 入门组] 字符串

Background

After consideration by the administrators, we plan to store the unofficial testdata separately in the last Subtask. These test points all have a score of 0, but failing to pass any of them will be considered as not passing this problem.

In this problem, there was an issue where the test point numbers in the judging records were in a mess. This was caused by a naming conflict in the unofficial testdata. However, we guarantee that their relative order is not mixed up.

Unofficial testdata provider: @tiger2005.

Problem Description

Kri really likes strings, so he prepares to study tt groups of strings.

In the ii-th study, Kri prepares two strings SS and RR. Here, SS has length nn and consists only of the three characters 0, 1, and - (note: the third character is a minus sign). Initially, RR is empty.

In each study, Zay comes to play with Kri, bringing a beautiful string TT of length mm. Kri is very envious that Zay has such a beautiful string, so he also wants to use strings SS and RR to produce string TT.

Specifically, Kri will perform nn operations. In each operation, Kri takes the first character of SS (denoted as cc) and deletes it from SS. If c=-c = \texttt{-}, then Kri must delete the first character or the last character of RR (the testdata guarantees that after deletion, RR is not empty). Otherwise, Kri appends cc to the end of RR.

After all operations are finished, Kri checks whether RR is equal to TT. If R=TR = T, Kri will feel happy; otherwise, Kri will feel sad.

For each study, how many different ways of operating will make Kri happy in the end? We define two plans as different if and only if, in some operation of some plan, Kri deletes the first character of RR, while in the corresponding operation of the other plan, Kri deletes the last character of RR.

Since the answer may be very large, you only need to output the remainder of the answer modulo 1,000,000,0071,000,000,007 (i.e. 109+710^9+7).

Input Format

The first line contains a positive integer tt.

Then there are tt test cases, representing tt studies of strings. For each test case:

The first line contains two positive integers n,mn, m, representing the lengths of strings SS and TT.

The second line is the string SS.

The third line is the string TT.

Output Format

Output tt lines in total. The ii-th line denotes the answer for the ii-th test case.

3
6 2
10-01-
01
7 3
010-1-1
101
6 4
111-00
1100
2
1
2
见附件中的 string2.in
见附件中的 string2.out

Hint

[Sample 1 Explanation]

For the first test case, there are two plans as follows:

  • The first - deletes the first character of RR, and the second - deletes the first character of RR.
  • The first - deletes the last character of RR, and the second - deletes the first character of RR.

[Constraints]

For 20%20\% of the testdata, n,m15n, m \le 15.

For 30%30\% of the testdata, n,m30n, m \le 30.

For 70%70\% of the testdata, n,m80n, m \le 80.

For the other 10%10\% of the testdata, it is guaranteed that the answer does not exceed 11.

For 100%100\% of the testdata, 1t51 \le t \le 5, 1n,m4001 \le n, m \le 400.

Translated by ChatGPT 5