#include <bits/stdc++.h>
using namespace std;
char o;
template <class O>
void read(O& x) {
  while (o = getchar(), o < '0' || o > '9')
    ;
  for (x = o ^ 48; o = getchar(), o >= '0' && o <= '9';) x = x * 10 + (o ^ 48);
}
const int L = 200005;
int tranc[L][26], len[L], pa[L], cnt, root, last;
inline int newnode(int l) {
  len[++cnt] = l;
  return cnt;
}
struct G {
  int v[L], next[L], h[L], tot;
  G() {
    tot = 0;
    memset(h, 0, sizeof h);
  }
  inline void add(int x, int y) { v[++tot] = y, next[tot] = h[x], h[x] = tot; }
} w, g, sav;
char s[L];
int seq[L], in[L], out[L], tclock;
void dfs(int x) {
  in[x] = ++tclock, seq[tclock] = x;
  for (int i = g.h[x]; i; i = g.next[i]) dfs(g.v[i]);
  out[x] = tclock;
}
struct Ask {
  int lab, l, r;
  Ask() {}
  Ask(int _lab, int _l, int _r) { lab = _lab, l = _l, r = _r; }
  bool operator<(const Ask& b) const { return r < b.r; }
} S[L];
int ans[L], lastins[L];
int first[L];
void ins(int x, int y) {
  for (; x <= cnt; x += x & -x) first[x] += y;
}
int qq(int x) {
  int t = 0;
  for (; x; x -= x & -x) t += first[x];
  return t;
}
int v[L];
void dfs2(int x) {
  v[x] += v[pa[x]];
  for (int i = g.h[x]; i; i = g.next[i]) dfs2(g.v[i]);
}
int n, lim;
void init(void) {
  cin >> n >> lim;
  int i, j, y, p, np, q, nq, tmp, Rep;
  for (root = newnode(0), i = 1; i <= n; ++i) {
    scanf("%s", s);
    int l = strlen(s);
    for (last = root, j = l - 1; j >= 0; --j) {
      if ((p = tranc[last][y = s[j] - 'a']) != 0) {
        if (len[p] == len[last] + 1)
          last = p;
        else {
          Rep = newnode(len[last] + 1);
          pa[Rep] = pa[p];
          pa[p] = Rep;
          memcpy(tranc[Rep], tranc[p], sizeof tranc[p]);
          for (tmp = last; tmp && tranc[tmp][y] == p; tmp = pa[tmp])
            tranc[tmp][y] = Rep;
          last = Rep;
        }
      } else {
        np = newnode(len[last] + 1);
        for (p = last; p && !tranc[p][y]; p = pa[p]) tranc[p][y] = np;
        if (!p)
          pa[np] = root;
        else {
          q = tranc[p][y];
          if (len[q] == len[p] + 1)
            pa[np] = q;
          else {
            nq = newnode(len[p] + 1), pa[nq] = pa[q];
            pa[np] = pa[q] = nq;
            memcpy(tranc[nq], tranc[q], sizeof tranc[q]);
            for (; p && tranc[p][y] == q; p = pa[p]) tranc[p][y] = nq;
          }
        }
        last = np;
      }
      w.add(last, i);
      sav.add(i, last);
    }
  }
}
void work(void) {
  for (register int i = 1; i <= cnt; ++i)
    if (pa[i]) g.add(pa[i], i);
  dfs(1);
  for (register int i = 1; i <= cnt; ++i) S[i] = Ask(i, in[i], out[i]);
  sort(S + 1, S + cnt + 1);
  for (int k = 1, i = 1; i <= cnt; ++i) {
    for (int j = w.h[seq[i]]; j; j = w.next[j]) {
      if (lastins[w.v[j]]) ins(lastins[w.v[j]], -1);
      ins(lastins[w.v[j]] = i, 1);
    }
    for (; S[k].r == i; ++k) ans[S[k].lab] = qq(S[k].r) - qq(S[k].l - 1);
  }
  for (register int i = 1; i <= cnt; ++i)
    v[i] = ans[i] >= lim ? len[i] - len[pa[i]] : 0;
  dfs2(1);
  long long nowans;
  int j;
  for (register int i = 1; i <= n; ++i) {
    if (i > 1) putchar(' ');
    for (nowans = 0, j = sav.h[i]; j; j = sav.next[j]) nowans += v[sav.v[j]];
    printf("%I64d", nowans);
  }
}
int main(void) {
  init(), work();
  return 0;
}
