Reading the stone slab

After each range replacement on a string, count the number of subsequences equal to a given name of length at most 5, modulo 1e9+7.

Medium7Dynamic programmingSegment treeStringNo attempts yetTime limit4sMemory limit256 MB

Problem

Seongwon was excavating an ancient site when he found a large stone slab, and he is decoding the text carved on it so he can report the find. Centuries of weather have worn the letters down, so many of them are hard to make out.

When the slab was carved, people liked to put the king's name on it. A slab counted as better the more ways there were to pick some of its letters (they do not have to be adjacent) and read them in order as the king's name. People also disliked long speech, so a king's name was never more than 5 letters.

Dating the slab told Seongwon which king reigned when it was buried, and now he wants to know how many ways that name can be read off the slab. The carving is faint, so as the study goes on the reading of parts of the slab keeps changing, and he wants the count again after every change. Help Seongwon by writing a program that computes it.

Input

The first line contains the number of test cases TT (1T101 \le T \le 10).

The first line of each test case contains the number of letters on the slab NN (1N2000001 \le N \le 200000), the length of the king's name MM (1M51 \le M \le 5), and the number of times the reading of the slab changes QQ (0Q1000000 \le Q \le 100000). The second line contains the first reading of the slab as a single string of uppercase English letters. The third line contains the king's name as a single string, also of uppercase English letters.

Each of the next QQ lines contains two integers AiA_i, BiB_i and a string SiS_i (1AiBiN1 \le A_i \le B_i \le N, the length of SiS_i is BiAi+1B_i - A_i + 1). This means the reading of the slab from its AiA_i-th letter through its BiB_i-th letter becomes SiS_i. Every SiS_i consists of uppercase English letters as well, and the total length of all SiS_i over all test cases is at most 2000000.

Output

For each test case print Q+1Q + 1 lines, one integer per line. On line ii print the number of ways to read the king's name off the ii-th reading of the slab. The answer can be large, so print it modulo 1000000007.