#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, K, lg[maxn], sa[maxn], st[maxn], ed[maxn], bel[maxn], num[maxn],
    cnt[maxn];
int tmp[maxn], rk[maxn], ht[maxn], a[maxn], buc[maxn], fir[maxn], sec[maxn],
    f[maxn][20];
char str[maxn], s[maxn];
void build_sa(int n) {
  copy(s + 1, s + n + 1, num + 1);
  sort(num + 1, num + n + 1);
  int *end = unique(num + 1, num + n + 1);
  for (int i = 1; i <= n; i++) a[i] = lower_bound(num + 1, end, s[i]) - num;
  memset(buc, 0, sizeof(buc));
  for (int i = 1; i <= n; i++) buc[a[i]]++;
  for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
  for (int i = 1; i <= n; i++) rk[i] = buc[a[i] - 1] + 1;
  for (int k = 1; k <= n; k <<= 1) {
    for (int i = 1; i <= n; i++) fir[i] = rk[i];
    for (int i = 1; i <= n; i++) sec[i] = i + k > n ? 0 : rk[i + k];
    memset(buc, 0, sizeof(buc));
    for (int i = 1; i <= n; i++) buc[sec[i]]++;
    for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
    for (int i = 1; i <= n; i++) tmp[n - --buc[sec[i]]] = i;
    memset(buc, 0, sizeof(buc));
    for (int i = 1; i <= n; i++) buc[fir[i]]++;
    for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
    for (int i = 1; i <= n; i++) sa[buc[fir[tmp[i]]]--] = tmp[i];
    bool unique = true;
    rk[sa[1]] = 1;
    for (int i = 1; i <= n; i++) {
      rk[sa[i]] = rk[sa[i - 1]];
      if (fir[sa[i]] == fir[sa[i - 1]] && sec[sa[i]] == sec[sa[i - 1]])
        unique = false;
      else
        rk[sa[i]]++;
    }
    if (unique) break;
  }
  for (int i = 1, k = 0; i <= n; i++) {
    if (k) k--;
    int j = sa[rk[i] - 1];
    while (i + k <= n && j + k <= n && a[i + k] == a[j + k]) k++;
    ht[rk[i]] = k;
  }
  for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; i++) f[i][0] = ht[i];
  for (int j = 1; j <= lg[n]; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int lcp(int x, int y) {
  int k = lg[y - x + 1];
  return min(f[x][k], f[y - (1 << k) + 1][k]);
}
bool check(int x, int y) {
  int p, q, l, r;
  if (ht[x + 1] < y)
    q = x;
  else {
    l = x + 1, r = m;
    while (l <= r) {
      int mid = (l + r) >> 1;
      lcp(x + 1, mid) >= y ? l = mid + 1 : r = mid - 1;
    }
    q = r;
  }
  if (ht[x] < y)
    p = x;
  else {
    l = 1, r = x - 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      lcp(mid + 1, x) >= y ? r = mid - 1 : l = mid + 1;
    }
    p = l;
  }
  return num[q] >= p;
}
int main() {
  scanf("%d %d", &n, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str), st[i] = m + 1;
    for (int j = 0; str[j]; j++) bel[++m] = i, s[m] = str[j];
    ed[i] = m, s[++m] = ' ';
  }
  build_sa(m);
  memset(num, 0, sizeof(num));
  for (int i = 1, j = 0, k = 1; i <= m; i++) {
    if (!bel[sa[i]]) continue;
    if (!cnt[bel[sa[i]]]++) j++;
    if (j >= K) {
      for (; j - (cnt[bel[sa[k]]] == 1) >= K; j -= !--(cnt[bel[sa[k++]]]))
        ;
      num[i] = k;
    }
  }
  for (int i = 1; i <= n; i++) {
    long long ans = 0;
    for (int j = st[i], k = 0; j <= ed[i]; j++) {
      for (k ? k-- : 0; k <= ed[i] - j && check(rk[j], k + 1); k++)
        ;
      ans += k;
    }
    printf("%lld ", ans);
  }
  return 0;
}
