#P9882. Nested String

Nested String

Nested String

Problem Description

Given two strings T1T_1 and T2T_2, a string XX is TT-nested if and only if XX can be represented as the string obtained by inserting T2T_2 at a position in T1T_1. For example, if T1=abcdT_1=\texttt{abcd} and T2=efT_2=\texttt{ef}, then efabcd\texttt{efabcd}, aefbcd\texttt{aefbcd} and abcdef\texttt{abcdef} are all TT-nested strings. Given strings SS, T1T_1, and T2T_2, your task is to compute the count of distinct TT-nested substrings in SS. Two nested substrings are considered distinct if they either occur at different positions in SS, or the insert positions of T2T_2 in T1T_1 are different . A substring of SS means a continuous sequence of characters from string SS.

Input

Ensure to use cin/cout and disable synchronization with stdio to avoid unexpected TLE verdict. The first line contains a single integer TT (1T201\le T\le 20), denoting the number of test cases. The first line of each test case contains two strings T1T_1 and T2T_2 (T1+T2S|T_1|+|T_2|\le |S|) separated by a single space. The second line of each test case contains a single string SS (S107|S|\le 10^7). It is guaranteed that SS, T1T_1, and T2T_2 all consist only of lowercase letters and S2×107\sum |S|\le 2\times 10^7. Here, S|S| means the length of string SS.

Output

For each test case, output an integer in a single line representing the number of distinct TT-nested substrings in SS.

Sample Input

3
abab ab
abababab
ab a
aaabbaabaa
aba ab
ababaabbabaab

Sample Output

6
5
5

Hint

In the first test case, the 66 TT-nested substrings are (the substring is underlined and the part from T2T_2 is highlighted in bold): abababab\underline{\textbf{ab}\text{abab}}\text{ab} abababab\underline{\text{ab}\textbf{ab}\text{ab}}\text{ab} abababab\underline{\text{abab}\textbf{ab}}\text{ab} abababab\text{ab}\underline{\textbf{ab}\text{abab}} abababab\text{ab}\underline{\text{ab}\textbf{ab}\text{ab}} abababab\text{ab}\underline{\text{abab}\textbf{ab}}

Source

2023“钉耙编程”中国大学生算法设计超级联赛(8)