#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
char ch[N], a[N];
int c[N], x[N], y[N], sa[N], h[N], rk[N], f[N][20], L[N];
int n, m, k, s[N], cnt[N], bel[N], len[N], lg[N], nn;
void build(int n, int m) {
  for (int i = 1; i <= m; i++) c[i] = 0;
  for (int i = 1; i <= n; i++) c[x[i] = s[i]]++;
  for (int i = 1; i <= m; i++) c[i] += c[i - 1];
  for (int i = n; i >= 1; i--) sa[c[x[i]]--] = i;
  int num;
  for (int k = 1; k <= n; k <<= 1) {
    num = 0;
    for (int i = n - k + 1; i <= n; i++) y[++num] = i;
    for (int i = 1; i <= n; i++)
      if (sa[i] > k) y[++num] = sa[i] - k;
    for (int i = 1; i <= m; i++) c[i] = 0;
    for (int i = 1; i <= n; i++) c[x[i]]++;
    for (int i = 1; i <= m; i++) c[i] += c[i - 1];
    for (int i = n; i >= 1; i--) sa[c[x[y[i]]]--] = y[i];
    swap(x, y);
    num = 1;
    x[sa[1]] = 1;
    for (int i = 2; i <= n; i++) {
      x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k])
                     ? num
                     : ++num;
    }
    if (num == n) return;
    m = num;
  }
}
void geth(int n) {
  memset(h, 0, sizeof(h));
  for (int i = 1; i <= n; i++) rk[sa[i]] = i;
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (rk[i] == 1) continue;
    if (k) k--;
    int j = sa[rk[i] - 1];
    while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) k++;
    h[rk[i]] = k;
  }
}
void pre(int n) {
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) f[i][0] = h[i];
  for (int j = 1; j <= 19; j++) {
    for (int i = 1; i <= n; i++) {
      if (i + (1 << j) - 1 > n) break;
      f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int lcp(int l, int r) {
  l++;
  int j = lg[r - l + 1];
  int ans = min(f[l][j], f[r - (1 << j) + 1][j]);
  return ans;
}
bool check(int x, int len) {
  int xl = 0, xr = 0;
  if (h[x] < len)
    xl = x;
  else {
    int l = 1, r = x - 1, ans = 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (lcp(mid, x) >= len)
        ans = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    xl = ans;
  }
  if (h[x + 1] < len)
    xr = x;
  else {
    int l = x + 1, r = n, ans = x + 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (lcp(x, mid) >= len)
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    xr = ans;
  }
  return L[xr] >= xl;
}
int main() {
  scanf("%d%d", &nn, &k);
  int fh = 30;
  for (int i = 1; i <= nn; i++) {
    scanf("%s", a + 1);
    int l = strlen(a + 1);
    len[i] = l;
    for (int j = 1; j <= l; j++) {
      s[++n] = a[j] - 'a' + 1;
      bel[n] = i;
    }
    s[++n] = ++fh;
  }
  build(n, fh);
  lg[1] = 0;
  for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  geth(n);
  pre(n);
  int tot = 0, p = 1;
  for (int i = 1; i <= n; i++) {
    if (!bel[sa[i]]) continue;
    if (cnt[bel[sa[i]]] == 0) tot++;
    cnt[bel[sa[i]]]++;
    while (tot > k || (tot == k && cnt[bel[sa[p]]] > 1)) {
      cnt[bel[sa[p]]]--;
      if (cnt[bel[sa[p]]] == 0) tot--;
      p++;
    }
    if (tot >= k)
      L[i] = p;
    else
      L[i] = -1;
  }
  for (int i = 1, st = 1; i <= nn; st += len[i++] + 1) {
    long long ans = 0;
    int k = 0;
    for (int j = st; j <= st + len[i] - 1; j++) {
      if (k) k--;
      while (j + k <= st + len[i] - 1 && check(rk[j], k + 1)) k++;
      ans += k;
    }
    printf("%I64d", ans);
    if (i < nn) printf(" ");
  }
  printf("\n");
  return 0;
}
