#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll tree[200001][26],fail[200001],end1[200001];
ll head[200001],to[200001],nxt[200001];
ll times[200001];
ll tot=1;
ll n;
ll cnt;
void insert(ll x,string s){
ll p=1;
for(ll i=0;i<s.length();i++){
ll ch=s[i]-'a';
if(tree[p][ch]==0) tree[p][ch]=++tot;
p=tree[p][ch];
}
end1[x]=p;
}
void get_fail(){
queue<ll>q;
for(ll i=0;i<=25;i++)
if(tree[1][i])
fail[tree[1][i]]=1,q.push(tree[1][i]);
while(!q.empty()){
ll p=q.front();
q.pop();
for(ll i=0;i<=25;i++){
if(tree[p][i]==0)
tree[p][i]=tree[fail[p]][i];
else{
fail[tree[p][i]]=tree[fail[p]][i];
q.push(tree[p][i]);
}
}
}
}
void add(ll x,ll y){
to[++cnt]=y;
nxt[cnt]=head[x];
head[x]=cnt;
}
void dfs(ll x){
for(ll i=head[x];i;i=nxt[i]){
ll y=to[i];
dfs(y);
times[x]+=times[y];
}
}
int main(){
scanf("%lld",&n);
for(ll i=1;i<=n;i++){
string s;
cin>>s;
insert(i,s);
}
get_fail();
string s;
cin>>s;
for(ll i=0,p=1;i<s.length();i++){
ll ch=s[i]-'a';
p=tree[p][ch];
times[p]++;
}
for(ll i=1;i<=tot;i++)
add(fail[i],i);
dfs(1);
for(ll i=1;i<=n;i++)
cout<<times[end1[i]]<<endl;
return 0;
}