#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct state {
  int link, len, next[26];
} st[N];
int ncnt, last;
inline void Extend(char c) {
  c -= 'a';
  int cur = st[last].next[c];
  if (cur) {
    if (st[cur].len == st[last].len + 1)
      last = cur;
    else {
      int r = ++ncnt;
      st[r].len = st[last].len + 1;
      st[r].link = st[cur].link;
      st[cur].link = r;
      for (int i = 0; i < 26; i++) st[r].next[i] = st[cur].next[i];
      for (int p = last; p != -1 && st[p].next[c] == cur; p = st[p].link)
        st[p].next[c] = r;
      last = r;
    }
  } else {
    cur = ++ncnt;
    int p;
    st[cur].len = st[last].len + 1;
    for (p = last; p != -1 && !st[p].next[c]; p = st[p].link)
      st[p].next[c] = cur;
    if (p == -1)
      st[cur].link = 0;
    else {
      int q = st[p].next[c];
      if (st[q].len == st[p].len + 1)
        st[cur].link = q;
      else {
        int nq = ++ncnt;
        st[nq].len = st[p].len + 1;
        st[nq].link = st[q].link;
        for (int i = 0; i < 26; i++) st[nq].next[i] = st[q].next[i];
        for (; p != -1 && st[p].next[c] == q; p = st[p].link)
          st[p].next[c] = nq;
        st[q].link = st[cur].link = nq;
      }
    }
    last = cur;
  }
}
int tmp[N], sum[N];
int n, K;
int l[N], r[N];
char S[N];
inline void Sort() {
  for (int i = 0; i <= ncnt; i++) sum[st[i].len]++;
  for (int i = 1; i <= r[n]; i++) sum[i] += sum[i - 1];
  for (int i = 0; i <= ncnt; i++) tmp[sum[st[i].len]--] = i;
}
set<int> Set[N];
int f[N];
long long ans[N];
int main() {
  scanf("%d%d", &n, &K);
  st[0].link = -1;
  for (int i = 1; i <= n; i++) {
    l[i] = r[i - 1] + 1;
    scanf("%s", S + l[i]);
    r[i] = l[i] + strlen(S + l[i]) - 1;
    for (int j = l[i]; j <= r[i]; j++) Extend(S[j]);
    last = 0;
  }
  Sort();
  for (int i = 1; i <= n; i++) {
    int p = 0;
    for (int j = l[i]; j <= r[i]; j++) {
      p = st[p].next[S[j] - 'a'];
      Set[p].insert(i);
    }
  }
  for (int i = ncnt + 1; i > 1; i--) {
    int x = tmp[i];
    f[x] = Set[x].size();
    int p = st[x].link;
    if (Set[x].size() > Set[p].size()) swap(Set[x], Set[p]);
    for (set<int>::iterator it = Set[x].begin(); it != Set[x].end(); it++)
      Set[p].insert(*it);
  }
  if (K > n) {
    for (int i = 1; i <= n; i++) printf("0 ");
    return 0;
  }
  f[0] = Set[0].size();
  for (int i = 1; i <= n; i++) {
    int p = 0;
    for (int j = l[i]; j <= r[i]; j++) {
      p = st[p].next[S[j] - 'a'];
      while (f[p] < K) p = st[p].link;
      ans[i] += st[p].len;
    }
    printf("%I64d ", ans[i]);
  }
  return 0;
}
