Little Q is now checking whether string A matches B. Two strings are considered matched if they have the same length, and there is no position i that Ai is different from Bi . However, Little Q is a kind man, he forgives every person who hurt him. What’s more, he even forgives strings! He gives the string k opportunities, if there are no more than k positions i that Ai is different from Bi , then Little Q will also consider the two strings matched. Note that both of the strings may contain the wildcard character ‘*’, which can match exactly one any character, in such a case this pair won’t consume the forgiveness opportunities. Let’s denote occ(S, T) as the number of substrings in string S which matches T, two substrings are considered different if they start in different places. You will be given two strings S and T, write a program to compute the value of occ(S, T) for k = 0, 1, 2, . . . , |T|.
Input
The first line contains a single integer K (1 ≤ K ≤ 100), the number of test cases. For each test case: The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 200 000), denoting the length of S and the length of T. The second line contains a string S of length n. The third line contains a string T of length m. It is guaranteed that the sum of all n is at most 1 000 000. Both S and T can only contain the characters in {‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘*’}.
Output
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=524305;
const double pi=acos(-1.0);
struct comp{
double r,i;comp(double _r=0,double _i=0){r=_r,i=_i;}
comp operator+(const comp&x)const{return comp(r+x.r,i+x.i);}
comp operator-(const comp&x)const{return comp(r-x.r,i-x.i);}
comp operator*(const comp&x)const{return comp(r*x.r-i*x.i,r*x.i+i*x.r);}
comp conj(){return comp(r,-i);}
}w[N],ww[N],A[N],B[N];
int pos[N],Case,n,m,k,i,j,o,s[N],f[N],ans[N];char a[N],b[N];
inline void FFT(comp a[],int n,int o){
for(int i=1;i<n;i++)if(i<pos[i])swap(a[i],a[pos[i]]);
for(int d=0,k=__builtin_ctz(n);(1<<d)<n;d++){
int m=1<<d,m2=m<<1;
for(int i=0;i<n;i+=m2)for(int j=0;j<m;j++){
comp&A=a[i+j+m],&B=a[i+j],t=(o==1?w[j<<(k-d)]:ww[j<<(k-d)])*A;
A=B-t;B=B+t;
}
}
if(o==-1)for(int i=0;i<n;i++)a[i].r/=n;
}
int main(){
scanf("%d",&Case);
while(Case--){
scanf("%d%d%s%s",&n,&m,a,b);
reverse(b,b+m);
for(k=1;k<=n+m-2;k<<=1);
j=__builtin_ctz(k)-1;
for(i=0;i<k;i++)pos[i]=pos[i>>1]>>1|((i&1)<<j);
for(i=0;i<k;i++)w[i]=comp(cos(pi*i/k),sin(pi*i/k));
for(i=0;i<k;i++)ww[i]=w[i],ww[i].i*=-1;
for(i=0;i<n;i++){
s[i]=0;
if(i)s[i]+=s[i-1];
if(a[i]=='*')s[i]++;
}
int cnt=0;
for(i=0;i<m;i++)if(b[i]=='*')cnt++;
for(i=m-1;i<n;i++){
f[i]=cnt+s[i];
if(i>=m)f[i]-=s[i-m];
}
for(o=0;o<=10;o++){
char target=o+'0';
if(o==10)target='*';
for(i=0;i<k;i++)A[i]=comp(0,0);
for(i=0;i<n;i++)if(a[i]==target)A[i].r=1;
for(i=0;i<m;i++)if(b[i]==target)A[i].i=1;
FFT(A,k,1);
for(i=0;i<k;i++){
j=(k-i)&(k-1);
B[i]=(A[i]*A[i]-(A[j]*A[j]).conj())*comp(0,-0.25);
}
FFT(B,k,-1);
for(i=m-1;i<n;i++){
int tmp=((int)(B[i].r+0.5));
if(o<10)f[i]+=tmp;else f[i]-=tmp;
}
}
for(i=0;i<=m;i++)ans[i]=0;
for(i=m-1;i<n;i++)ans[m-f[i]]++;
for(i=0;i<=m;i++){
if(i)ans[i]+=ans[i-1];
printf("%d\n",ans[i]);
}
}
}