#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, k;
char s[N];
int a[N], len[N], bels[N], LEN;
int rk[N], sa[N], height[N];
void SA(int m = n + 26) {
  static int x[N], y[N], cnt[N];
  for (int i = 1; i <= m; ++i) cnt[i] = 0;
  for (int i = 1; i <= LEN; ++i) ++cnt[x[i] = a[i]];
  for (int i = 1; i <= m; ++i) cnt[i] += cnt[i - 1];
  for (int i = LEN; i >= 1; --i) sa[cnt[x[i]]--] = i;
  int p = 1;
  for (int k = 1; k <= LEN; k <<= 1) {
    int cur = 0;
    for (int i = LEN - k + 1; i <= LEN; ++i) y[++cur] = i;
    for (int i = 1; i <= LEN; ++i)
      if (sa[i] > k) y[++cur] = sa[i] - k;
    for (int i = 1; i <= m; ++i) cnt[i] = 0;
    for (int i = 1; i <= LEN; ++i) ++cnt[x[i]];
    for (int i = 1; i <= m; ++i) cnt[i] += cnt[i - 1];
    for (int i = LEN; i >= 1; --i) sa[cnt[x[y[i]]]--] = y[i];
    swap(x, y);
    x[sa[1]] = 1;
    p = 1;
    for (int i = 2; i <= LEN; ++i)
      x[sa[i]] = ((y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k])
                      ? p
                      : ++p);
    m = p;
  }
  memcpy(rk, x, sizeof(x));
}
int lg[N], mn[N][20];
void gethei() {
  for (int i = 1, k = 0; i <= LEN; ++i) {
    if (rk[i] == 1) continue;
    if (k) --k;
    int j = sa[rk[i] - 1];
    while (i + k <= LEN && j + k <= LEN && a[i + k] == a[j + k]) ++k;
    height[rk[i]] = mn[rk[i]][0] = k;
  }
  for (int i = 2; i <= LEN; ++i) lg[i] = lg[i >> 1] + 1;
  for (int j = 1; j <= 19; ++j)
    for (int i = 1; i + (1 << j) - 1 <= LEN; ++i)
      mn[i][j] = min(mn[i][j - 1], mn[i + (1 << (j - 1))][j - 1]);
}
int qmin(int l, int r) {
  int t = lg[r - l + 1];
  return min(mn[l][t], mn[r - (1 << t) + 1][t]);
}
struct persistent_sg {
  int num[N * 20], ls[N * 20], rs[N * 20];
  int cnt = 0;
  void update(int& p, int o, int v, int l = 0, int r = LEN + 1) {
    p = ++cnt;
    num[p] = num[o] + 1;
    ls[p] = ls[o];
    rs[p] = rs[o];
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (v <= mid)
      update(ls[p], ls[o], v, l, mid);
    else
      update(rs[p], rs[o], v, mid + 1, r);
  }
  int qnum(int p, int q, int L, int R, int l = 0, int r = LEN + 1) {
    if (L <= l && r <= R) return num[q] - num[p];
    int mid = (l + r) >> 1, ret = 0;
    if (L <= mid) ret += qnum(ls[p], ls[q], L, R, l, mid);
    if (R > mid) ret += qnum(rs[p], rs[q], L, R, mid + 1, r);
    return ret;
  }
} tr;
int root[N], ed[N];
long long res[N];
int check(int p, int len) {
  int l = 1, r = p - 1, ansl = p, ansr = p;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (qmin(mid + 1, p) >= len)
      ansl = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  l = p + 1, r = LEN;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (qmin(p + 1, mid) >= len)
      ansr = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  int colors = tr.qnum(root[ansl - 1], root[ansr], 0, ansl - 1);
  return colors;
}
int prv[N];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    len[i] = strlen(s + 1);
    for (int j = 1; j <= len[i]; ++j) a[++LEN] = s[j] - 'a' + 1, bels[LEN] = i;
    a[++LEN] = i + 26, bels[LEN] = 0;
    ed[i] = LEN;
  }
  SA();
  gethei();
  for (int i = 1; i <= LEN; ++i)
    tr.update(root[i], root[i - 1], prv[bels[sa[i]]]), prv[bels[sa[i]]] = i;
  for (int i = 1; i <= LEN; ++i) {
    if (bels[i] == 0) continue;
    int l = 1, r = ed[bels[i]] - i, ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(rk[i], mid) >= k)
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    res[bels[i]] += ans;
  }
  for (int i = 1; i <= n; ++i) printf("%lld ", res[i]);
  return 0;
}
