#include <bits/stdc++.h>
using namespace std;
const long long N = 300005;
char ss[N];
long long s[N], rak[N], tp[N], sa[N], t[N], h[N], lg[N], mp[N], st[N][31], L[N],
    R[N], mmp[N], n, m, nn, kk;
void sort() {
  for (long long i = 1; i <= m; i++) t[i] = 0;
  for (long long i = 1; i <= n; i++) t[rak[i]]++;
  for (long long i = 1; i <= m; i++) t[i] += t[i - 1];
  for (long long i = n; i >= 1; i--) sa[t[rak[tp[i]]]--] = tp[i];
}
void work() {
  m = n + 1000;
  for (long long i = 1; i <= n; i++) rak[i] = s[i], tp[i] = i;
  sort();
  for (long long w = 1, p = 0; p < n; m = p, w <<= 1) {
    p = 0;
    for (long long i = 1; i <= w; i++) tp[++p] = n - w + i;
    for (long long i = 1; i <= n; i++)
      if (sa[i] > w) tp[++p] = sa[i] - w;
    sort();
    for (long long i = 1; i <= n; i++) tp[i] = rak[i];
    p = 0;
    for (long long i = 1; i <= n; i++)
      rak[sa[i]] =
          (tp[sa[i - 1]] == tp[sa[i]] && tp[sa[i - 1] + w] == tp[sa[i] + w]
               ? p
               : ++p);
  }
  long long k = 0;
  for (long long i = 1; i <= n; i++) {
    if (k) k--;
    long long j = sa[rak[i] - 1];
    while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) k++;
    h[rak[i]] = k;
  }
}
void rmq() {
  for (long long i = 1; i <= n; i++) st[i][0] = h[i];
  for (long long i = 1; i <= 30; i++) {
    for (long long j = 1; j + (1 << i) - 1 <= n; j++) {
      st[j][i] = min(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
    }
  }
}
long long lcp(long long x, long long y) {
  if (x > y) swap(x, y);
  x++;
  long long z = lg[y - x + 1];
  return min(st[x][z], st[y - (1 << z) + 1][z]);
}
long long workk(long long x, long long len) {
  long long ll, rr;
  if (h[x] < len)
    ll = x;
  else {
    long long l = 1, r = x - 1;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (lcp(x, mid) >= len)
        r = mid - 1, ll = mid;
      else
        l = mid + 1;
    }
  }
  if (h[x + 1] < len)
    rr = x;
  else {
    long long l = x + 1, r = n;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (lcp(mid, x) >= len)
        l = mid + 1, rr = mid;
      else
        r = mid - 1;
    }
  }
  return mmp[rr] >= ll;
}
signed main() {
  for (long long i = 2; i < N; i++) lg[i] = lg[i >> 1] + 1;
  scanf("%lld%lld", &nn, &kk);
  for (long long i = 1; i <= nn; i++) {
    scanf("%s", ss + 1);
    long long len = strlen(ss + 1);
    L[i] = n + 1;
    for (long long j = 1; j <= len; j++) s[++n] = ss[j], mp[n] = i;
    R[i] = n;
    s[++n] = 'z' + i;
  }
  work();
  rmq();
  for (long long i = 1; i <= nn; i++) t[i] = 0;
  for (long long i = 1, sum = 0, h = 1; i <= n; i++) {
    if (!mp[sa[i]]) break;
    if (!t[mp[sa[i]]]) sum++;
    t[mp[sa[i]]]++;
    while (sum > kk || (sum == kk && t[mp[sa[h]]] > 1)) {
      t[mp[sa[h]]]--;
      if (!t[mp[sa[h++]]]) sum--;
    }
    if (sum == kk) mmp[i] = h;
  }
  for (long long i = 1; i <= nn; i++) {
    long long ans = 0, anss = 0;
    for (long long j = L[i]; j <= R[i]; j++) {
      anss = max(anss - 1, 0ll);
      while (j + anss <= R[i] && workk(rak[j], anss + 1)) anss++;
      ans += anss;
    }
    printf("%lld ", ans);
  }
  printf("\n");
  return 0;
}
