#include <bits/stdc++.h>
using namespace std;
int n, m, last;
int nxt[200200][26], link[200200], dp[200200], cnt[200200], ord[200200],
    f[200200];
void extend(int c) {
  if (nxt[last][c] && dp[nxt[last][c]] == dp[last] + 1) {
    last = nxt[last][c];
    return;
  }
  int x = last, y = last = ++m;
  dp[y] = dp[x] + 1;
  while (x && !nxt[x][c]) nxt[x][c] = y, x = link[x];
  if (!x)
    link[y] = 1;
  else {
    int z = nxt[x][c];
    if (dp[z] == dp[x] + 1)
      link[y] = z;
    else {
      int u = ++m;
      memcpy(nxt[u], nxt[z], sizeof nxt[u]);
      link[u] = link[z], link[z] = link[y] = u;
      dp[u] = dp[x] + 1;
      while (x && nxt[x][c] == z) nxt[x][c] = u, x = link[x];
    }
  }
}
int k, least, vis[200200];
string s[200200];
int main() {
  cin >> k >> least;
  last = ++m;
  for (int i = 1; i <= k; i++) {
    last = 1;
    cin >> s[i];
    for (int j = 0; j < s[i].size(); j++) extend(s[i][j] - 'a');
    n = max(n, (int)s[i].size());
  }
  for (int i = 1; i <= m; i++) cnt[dp[i]]++;
  for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1];
  for (int i = 1; i <= m; i++) ord[cnt[dp[i]]--] = i;
  for (int i = 1; i <= k; i++) {
    int x = 1;
    for (int j = 0; j < s[i].size(); j++) {
      int c = s[i][j] - 'a';
      x = nxt[x][c];
      for (int y = x; y && vis[y] != i; y = link[y]) f[y]++, vis[y] = i;
    }
  }
  for (int i = 1; i <= m; i++) f[i] = (f[i] >= least) ? dp[i] - dp[link[i]] : 0;
  for (int i = 1; i <= m; i++) f[ord[i]] += f[link[ord[i]]];
  for (int i = 1; i <= k; i++) {
    long long ans = 0;
    int x = 1;
    for (int j = 0; j < s[i].size(); j++) {
      int c = s[i][j] - 'a';
      x = nxt[x][c];
      ans += f[x];
    }
    cout << ans << (i < k ? ' ' : '\n');
  }
  return 0;
}
