1 #include<stdio.h>
2 #include<string.h>
3 int next[12],la,lb;
4 void GetNext(char T[])
5 {
6 int j=1,k=0;
7 next[1]=0;
8 while(j<=la)
9 {
10 if(k==0||T[j]==T[k])
11 {
12 ++j;
13 ++k;
14 if(T[k]==T[j])
15 next[j]=next[k];
16 else
17 next[j]=k;
18 }
19 else
20 k=next[k];
21 }
22 }
23 int KMP(char S[],char T[])
24 {
25 int j,k,count;
26 for(k=1,count=0;k<=lb-la+1;count++,k=k-la+1)
27 {
28 j=1;
29 while(j<=la&&k<=lb)
30 {
31 if(j==0||S[k]==T[j]){++k;++j;}
32 else j=next[j];
33 }
34 if(j<=la) break;
35 }
36 return count;
37 }
38 int main()
39 {
40 int n;
41 char a[12],b[1002];
42 scanf("%d",&n);
43 while(n--)
44 {
45 scanf("%s%s",a+1,b+1);
46 la=strlen(a+1);lb=strlen(b+1);
47 GetNext(a);
48 printf("%d\n",KMP(b,a));
49 }
50 return 0;
51 }