#include <bits/stdc++.h>
using namespace std;
int trie[200010][26], fail[200010], res[200010], id[200010], que[200010], tot, len, n, a, b(1);
char s[2000010];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s + 1;
len = strlen(s + 1);
for (int j = 1; j <= len; ++j) {
int ch = s[j] - 'a';
if (!trie[id[i]][ch]) trie[id[i]][ch] = ++tot;
id[i] = trie[id[i]][ch];
}
}
for (int i = 0; i < 26; ++i) if (trie[0][i]) que[++a] = trie[0][i];
while (b <= a) {
int u = que[b++];
for (int i = 0; i < 26; ++i) {
if (trie[u][i]) {
fail[trie[u][i]] = trie[fail[u]][i];
que[++a] = trie[u][i];
} else trie[u][i] = trie[fail[u]][i];
}
}
cin >> s + 1;
len = strlen(s + 1);
for (int i = 1, p = 0; i <= len; ++i) {
int ch = s[i] - 'a';
p = trie[p][ch];
res[p]++;
}
for (int i = tot; i >= 1; --i) res[fail[que[i]]] += res[que[i]];
for (int i = 1; i <= n; ++i) cout << res[id[i]] << "\n";
}