#include"stdio.h" #include"string.h" char a[1000010], b[10010] ; int next[10010] = {-1} ; void getnext(char p[],int leth) { int i,j=-1; for(i=1;i<leth;i++) { while(j!=-1&&p[i]!=p[j+1])j=next[j]; if(p[i]==p[j+1])j++; next[i]=j; } } int kmp(char t[],char p[],int leth1,int leth2) { int i,j=-1; int count=0; getnext(p,leth2); for(i=0;i<leth1;i++) { while(j!=-1&&t[i]!=p[j+1])j=next[j]; if(t[i]==p[j+1])j++; if(j==leth2-1) count++; } return count; } int main( ) { int t; scanf("%d",&t); while(t--) { scanf("%s%s",b,a); printf("%d\n",kmp(a,b,strlen(a),strlen(b))); } return 0; }