#include <bits/stdc++.h>
#define int long long
using namespace std;
int n; string t[205];
struct AC {
struct ACnode {
int son[26] , fail , end;
} tr[5000005]; int tot;
int cnt[5000005] , a[100005];
void insert(const string &s , int x) {
int p = 0;
for (int i = 0; i < s.size(); i++) {
if (!tr[p].son[s[i] - 'a']) tr[p].son[s[i] - 'a'] = ++tot;
p = tr[p].son[s[i] - 'a'];
cnt[p]++;
}
tr[p].end++;
a[x] = p;
}
void getfail() {
queue <int> q;
for (int i = 0; i < 26; i++) {
if (tr[0].son[i]) {
q.push(tr[0].son[i]);
tr[tr[0].son[i]].fail = 0;
}
}
int u;
while(!q.empty()) {
u = q.front(); q.pop();
for (int i = 0; i < 26; i++) {
if (tr[u].son[i]) {
tr[tr[u].son[i]].fail = tr[tr[u].fail].son[i];
q.push(tr[u].son[i]);
} else {
tr[u].son[i] = tr[tr[u].fail].son[i];
}
}
}
}
void query() {
for (int i = tot; i >= 0; i--) cnt[tr[i].fail] += cnt[i];
for (int i = 1; i <= n; i++) cout << cnt[a[i]] << '\n';
}
} ac;
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> t[i] , ac.insert(t[i] , i);
ac.getfail();
ac.query();
return 0;
}
悬小号一关