#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=30010;
int next[maxn];
string s1,s2;
int ans=0;
void getfail(){
next[0]=0; next[1]=0;
for (int i=1;i<s1.size();++i){
int j=next[i];
while (j!=0&&s1[i]!=s1[j]) j=next[j];
if (s1[i]==s1[j]) next[i+1]=j+1;
else next[i+1]=0;
}
}
void kmp(){
int j=0;
for (int i=0;i<s2.size();++i){
while (j&&s2[i]!=s1[j]) j=next[j];
if (s2[i]==s1[j]) j++;
if (j==s1.size()) ans++;
}
}
int main()
{
freopen("oulipo.in","r",stdin);
freopen("oulipo.out","w",stdout);
int t;
scanf("%d",&t);
while (t--){
cin>>s1>>s2;
getfail();
ans=0;
kmp();
printf("%d\n",ans);
}
}