3050: Broken String

时间限制:4000 ms 内存限制:128 MB
上传者:
提交:4 通过:3

题目描述

$Aguin$ has one string $A$ with the length of $n$ and one string $B$ with the length of $m$. Both of them contains only lowercase letters. But the strings are such antiques that some characters can't be recognized (replaced with '$*$'), and it can be any lowercase letters.

Now $Aguin$ is wondering whether $A$ is a substring of $B$. However, his way of match is a little strange. The detailed rules for match are as follows : the beginning of the $A$ is aligned with the $i^{th}$ character of the $B$, and every character in the $A$ can find the same one in $B$, and the position deviation does not exceed the $k$, then it is considered that $A$ is matched with $B$ in the subordinate position of the $B$. That is to say, for all $j (1 \leq j \leq |A|)$, there is a $p (1 \leq p \leq |B|)$, which satisfies $|j-(p-i+1)| \leq k$, $i+j \leq m$ and $A[j]=B[p]$.

For example, string $"abc"$ can be matched in the $2^{nd}$ location of $"aabbc"$. 


And if $k=0$, string "***" can be matched with any other strings which length is $3$.

Given strings $A$, $B$ and the number $k$, you are supposed to find how many locations can $A$ be matched in $B$.

输入格式

The first line contains an integer number $T$, the number of test cases.

For each test case :
The first line contains three integers $n, m(1 \leq n \leq m \leq 10^{5}), k(1 \leq k \leq 10^{5})$, length of $A$, $B$ and the number of deviation.

The second line contains a string $A$ with the length of $n$.

The third line contains a string $BT$ with the length of $m$.

It is guaranteed that the strings contains only lowercase letters and '*'.

输出格式

For each test case print the number of locations can $S$ be matched in $T$.

输入样例 复制

4
3 5 1
abc
aabbc
3 5 1
a**
aabbc
3 5 1
abc
a*b*c
3 5 1
a*a
aabbb

输出样例 复制

2
3
3
1