#include<cstdio>
#include<cstring>
using namespace std;
const int SEED=13131;
unsigned long long s[1000005];
unsigned long long p[1000005];
int n;
bool examin(int pos,unsigned long long s[],unsigned long long hash_a,int len)
{
int tail=pos+len-1;
if(hash_a==s[pos+len-1]-s[pos-1]*p[len])
{
return true;
}
else
{
return false;
}
}
int main()
{
scanf("%d",&n);
p[0]=1;
for(int i=1;i<=1000005;i++)
{
p[i]=p[i-1]*SEED;
}
for(int e=1;e<=n;e++)
{
int cnt=0;
char a[10005],b[1000005];
scanf("%s%s",a+1,b+1);
int lenA=strlen(a+1);
int lenB=strlen(b+1);
unsigned long long hash_a=0;
for(int i=1;i<=lenA;i++)
{
hash_a=hash_a*SEED+(a[i]-'0');
}
s[0]=0;
for(int i=1;i<=lenB;i++)
{
s[i]=s[i-1]*SEED+(b[i]-'0');
}
for(int i=1;i+lenA-1<=lenB;i++)
{
if(examin(i,s,hash_a,lenA))
{
cnt++;
}
}
printf("%d\n",cnt);
}
return 0;
}
#include<cstring>
using namespace std;
const int SEED=13131;
unsigned long long s[1000005];
unsigned long long p[1000005];
int n;
bool examin(int pos,unsigned long long s[],unsigned long long hash_a,int len)
{
int tail=pos+len-1;
if(hash_a==s[pos+len-1]-s[pos-1]*p[len])
{
return true;
}
else
{
return false;
}
}
int main()
{
scanf("%d",&n);
p[0]=1;
for(int i=1;i<=1000005;i++)
{
p[i]=p[i-1]*SEED;
}
for(int e=1;e<=n;e++)
{
int cnt=0;
char a[10005],b[1000005];
scanf("%s%s",a+1,b+1);
int lenA=strlen(a+1);
int lenB=strlen(b+1);
unsigned long long hash_a=0;
for(int i=1;i<=lenA;i++)
{
hash_a=hash_a*SEED+(a[i]-'0');
}
s[0]=0;
for(int i=1;i<=lenB;i++)
{
s[i]=s[i-1]*SEED+(b[i]-'0');
}
for(int i=1;i+lenA-1<=lenB;i++)
{
if(examin(i,s,hash_a,lenA))
{
cnt++;
}
}
printf("%d\n",cnt);
}
return 0;
}