#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
char s[maxn << 1];
int n, K, mx, l[maxn], st[maxn];
int cnt[maxn], rnk[maxn << 1];
int tot = 1, ch[maxn << 1][26], link[maxn << 1], len[maxn << 1], rt[maxn << 1];
struct Segmenttree {
  int tot, ch[maxn << 5][2], siz[maxn << 5];
  void insert(int &p, int l, int r, int pos) {
    if (!p) p = ++tot;
    if (l == r) {
      siz[p] = 1;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      insert(ch[p][0], l, mid, pos);
    else
      insert(ch[p][1], mid + 1, r, pos);
    siz[p] = siz[ch[p][0]] + siz[ch[p][1]];
  }
  int merge(int x, int y, int l, int r) {
    if (!x || !y) return x + y;
    int p = ++tot;
    if (l == r) {
      siz[p] = siz[x] | siz[y];
      return p;
    }
    int mid = (l + r) >> 1;
    ch[p][0] = merge(ch[x][0], ch[y][0], l, mid);
    ch[p][1] = merge(ch[x][1], ch[y][1], mid + 1, r);
    siz[p] = siz[ch[p][0]] + siz[ch[p][1]];
    return p;
  }
} T;
int extend(int c, int p) {
  if (ch[p][c]) {
    int q = ch[p][c];
    if (len[q] == len[p] + 1) return q;
    int cur = ++tot;
    len[cur] = len[p] + 1;
    memcpy(ch[cur], ch[q], sizeof ch[q]);
    for (; p && ch[p][c] == q; p = link[p]) ch[p][c] = cur;
    link[cur] = link[q], link[q] = cur;
    return cur;
  }
  int cur = ++tot;
  len[cur] = len[p] + 1;
  for (; p && !ch[p][c]; p = link[p]) ch[p][c] = cur;
  if (!p)
    link[cur] = 1;
  else {
    int q = ch[p][c];
    if (len[q] == len[p] + 1)
      link[cur] = q;
    else {
      int clone = ++tot;
      len[clone] = len[p] + 1;
      memcpy(ch[clone], ch[q], sizeof ch[q]);
      for (; p && ch[p][c] == q; p = link[p]) ch[p][c] = clone;
      link[clone] = link[q], link[q] = link[cur] = clone;
    }
  }
  return cur;
}
inline void build() {
  for (int i = 1; i <= tot; i++) ++cnt[len[i]];
  for (int i = 1; i <= mx; i++) cnt[i] += cnt[i - 1];
  for (int i = tot; i >= 1; i--) rnk[cnt[len[i]]--] = i;
  for (int i = tot; i >= 2; i--) {
    int t = rnk[i];
    rt[link[t]] = T.merge(rt[link[t]], rt[t], 1, n);
  }
}
int main() {
  scanf("%d%d", &n, &K);
  tot = 1;
  for (int i = 1, lst = 1; i <= n; i++) {
    scanf("%s", s + lst);
    st[i] = lst - 1, l[i] = strlen(s + lst), mx = max(mx, l[i]);
    lst = lst + l[i], s[lst++] = '#';
    for (int j = 1, now = 1; j <= l[i]; j++)
      now = extend(s[st[i] + j] - 'a', now), T.insert(rt[now], 1, n, i);
  }
  build();
  for (int i = 1; i <= n; i++) {
    long long ans = 0;
    for (int j = 1, now = 1; j <= l[i]; j++) {
      now = ch[now][s[st[i] + j] - 'a'];
      while (now && T.siz[rt[now]] < K) now = link[now];
      ans += len[now];
    }
    cout << ans << ' ';
  }
  return 0;
}
