#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 7;
const long long MOD = 1e9 + 7;
const int CHARSET_SIZE = 26;
string s[MAXN];
int n, k;
struct Suffix_Automaton {
  int cnt, root, last, prt[MAXN << 1], son[MAXN << 1][CHARSET_SIZE],
      vis[MAXN << 1], tot[MAXN << 1], mx[MAXN << 1];
  long long size[MAXN << 1];
  int topo[MAXN << 1], buc[MAXN << 1];
  inline void init() {
    for (int i = 1; i <= cnt; i++)
      for (int j = 0; j < CHARSET_SIZE; j++) son[i][j] = 0;
    root = last = cnt = 1;
    size[cnt] = mx[cnt] = prt[cnt] = 0;
  }
  inline void extend(int c, int id) {
    int p = last;
    if (son[p][c]) {
      int q = son[p][c];
      if (mx[q] == mx[p] + 1) {
        last = q;
      } else {
        int nq = ++cnt;
        memcpy(son[nq], son[q], sizeof(son[q]));
        size[nq] = 0;
        mx[nq] = mx[p] + 1;
        prt[nq] = prt[q];
        prt[q] = nq;
        for (; p && son[p][c] == q; p = prt[p]) son[p][c] = nq;
        last = nq;
      }
      return;
    }
    int np = ++cnt;
    mx[np] = mx[p] + 1;
    size[np] = 1;
    for (; p && !son[p][c]; p = prt[p]) son[p][c] = np;
    if (!p)
      prt[np] = root;
    else {
      int q = son[p][c];
      if (mx[q] == mx[p] + 1)
        prt[np] = q;
      else {
        int nq = ++cnt;
        memcpy(son[nq], son[q], sizeof(son[q]));
        size[nq] = 0;
        mx[nq] = mx[p] + 1;
        prt[nq] = prt[q];
        prt[q] = prt[np] = nq;
        for (; p && son[p][c] == q; p = prt[p]) son[p][c] = nq;
      }
    }
    last = np;
  }
  void toposort() {
    int maxv = 0;
    memset(buc, 0, sizeof(buc));
    for (int i = 1; i <= cnt; i++) {
      buc[mx[i]]++;
      maxv = max(maxv, mx[i]);
    }
    for (int i = 1; i <= maxv; i++) buc[i] += buc[i - 1];
    for (int i = cnt; i >= 1; i--) topo[buc[mx[i]]--] = i;
  }
  void cal_right() {
    toposort();
    for (int i = 2; i <= cnt; i++) {
      int v = topo[i];
      size[v] = size[prt[v]] + (tot[v] >= k ? mx[v] - mx[prt[v]] : 0);
    }
  }
  void solve() {
    for (int i = 1; i <= n; i++) {
      long long nt = root, ans = 0;
      for (int j = 0; s[i][j]; j++) {
        nt = son[nt][s[i][j] - 'a'];
        ans += size[nt];
      }
      printf("%lld ", ans);
    }
  }
} sam;
int main() {
  int las;
  scanf("%d%d", &n, &k);
  sam.init();
  for (int i = 1; i <= n; i++) {
    sam.last = sam.root;
    cin >> s[i];
    for (int j = 0; s[i][j]; j++) {
      sam.extend(s[i][j] - 'a', i);
    }
  }
  for (int i = 1; i <= n; i++) {
    sam.last = 1;
    for (int j = 0; s[i][j]; j++) {
      sam.last = sam.son[sam.last][s[i][j] - 'a'];
      las = sam.last;
      while (las && sam.vis[las] != i) {
        sam.tot[las]++;
        sam.vis[las] = i;
        las = sam.prt[las];
      }
    }
  }
  sam.cal_right();
  sam.solve();
}
