#include <iostream>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 10010;
int n;
int ne[N]; //KMP的next数组
char s[N], p[N]; //s是主串(也称目标串),p是短串(也称模式串)
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> (p + 1); //从1下标开始存储,方便计算
int plen = strlen(p + 1);
for (int i = 2, j = 0; i <= plen; i ++ ) //预处理出p串的ne数组
{
while (j && p[i] != p[j + 1]) j = ne[j];
if (p[i] == p[j + 1]) j ++ ;
ne[i] = j;
}
while(n--)
{
cin >> (s + 1); //从1下标开始存储,方便计算
int slen = strlen(s + 1);
int cnt = 0;
for (int i = 1, j = 0; i <= slen; i ++ ) //KMP查找
{
while (j && s[i] != p[j + 1]) j = ne[j];
if (s[i] == p[j + 1]) j ++ ; //当前字符匹配
if (j == plen) //匹配成功
{
cnt++;
j = ne[j];
}
}
cout << cnt << "\n";
}
return 0;
}