#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int MAXLEN = 200000;
const int MAXLOG = 19;
const int INF = 0x3f3f3f3f;
template <class T>
void Read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = 0;
  while (c < '0' || '9' < c) {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (flag) x = -x;
}
namespace SA {
int sa[MAXLEN + 10], ws[MAXLEN + 10];
int wa[MAXLEN + 10], wb[MAXLEN + 10];
int tmp[MAXLEN + 10];
bool cmp(int *x, int p1, int p2, int len) {
  return x[p1] == x[p2] && x[p1 + len] == x[p2 + len];
}
void getsa(int *A, int n, int m) {
  A[n] = 0;
  int i, j, p = 0, *x = wa, *y = wb;
  for (i = 0; i <= m; ++i) ws[i] = 0;
  for (i = 1; i <= n; ++i) ++ws[x[i] = A[i]];
  for (i = 1; i <= m; ++i) ws[i] += ws[i - 1];
  for (i = n; i >= 1; --i) sa[ws[x[i]]--] = i;
  for (j = 1, p = 1; p < n; j <<= 1, m = p) {
    for (p = 0, i = n - j + 1; i <= n; ++i) y[++p] = i;
    for (i = 1; i <= n; ++i)
      if (sa[i] > j) y[++p] = sa[i] - j;
    for (i = 1; i <= n; ++i) tmp[i] = x[y[i]];
    for (i = 0; i <= m; ++i) ws[i] = 0;
    for (i = 1; i <= n; ++i) ++ws[tmp[i]];
    for (i = 1; i <= m; ++i) ws[i] += ws[i - 1];
    for (i = n; i >= 1; --i) sa[ws[tmp[i]]--] = y[i];
    for (swap(x, y), i = 1, p = 0; i <= n; ++i)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p : ++p;
  }
}
int ranks[MAXLEN + 10], height[MAXLEN + 10];
inline void getheight(int *A, int n) {
  for (int i = 1; i <= n; ++i) ranks[sa[i]] = i;
  for (int i = 1, j, k = 0; i <= n; height[ranks[i++]] = k)
    for (k ? --k : 0, j = sa[ranks[i] - 1]; A[i + k] == A[j + k]; ++k)
      ;
}
}  // namespace SA
int n, k, m, maxlog;
char str[MAXN + 10];
int A[MAXLEN + 10], t[MAXLEN + 10];
int ed[MAXN + 10], id[MAXLEN + 10];
int mnval[MAXLEN + 10][MAXLOG + 5];
int mlog2[MAXLEN + 10];
void init() {
  maxlog = log(m) / log(2);
  for (int i = 1; i <= m; ++i) mnval[i][0] = SA::height[i];
  for (int len = 1; len <= maxlog; ++len)
    for (int i = (1 << (len - 1)); i <= m; ++i)
      mnval[i][len] =
          min(mnval[i][len - 1], mnval[i - (1 << (len - 1))][len - 1]);
  for (int i = 1, j = 0; i <= m; ++i, (1 << (j + 1)) <= i ? ++j : 0)
    mlog2[i] = j;
}
int getmn(int l, int r) {
  if (l == r) return ed[id[SA::sa[l]]] - SA::sa[l] + 1;
  int t = mlog2[r - l];
  return min(mnval[l + (1 << t)][t], mnval[r][t]);
}
int mx[MAXLEN * 4];
inline void pushdown(int x) {
  mx[x << 1] = max(mx[x << 1], mx[x]);
  mx[x << 1 | 1] = max(mx[x << 1 | 1], mx[x]);
}
void insert(int x, int l, int r, int v, int ll, int rr) {
  if (l <= ll && rr <= r)
    mx[x] = max(mx[x], v);
  else {
    int mid = (ll + rr) >> 1;
    if (l <= mid) insert(x << 1, l, r, v, ll, mid);
    if (mid < r) insert(x << 1 | 1, l, r, v, mid + 1, rr);
  }
}
void getall(int x, int l, int r, long long int *ans) {
  if (l == r)
    ans[id[SA::sa[l]]] += mx[x];
  else {
    pushdown(x);
    int mid = (l + r) >> 1;
    getall(x << 1, l, mid, ans);
    getall(x << 1 | 1, mid + 1, r, ans);
  }
}
int vis[MAXN + 10], tot;
int tag[MAXLEN + 10];
inline void ins(int x) {
  if (!id[SA::sa[x]]) return;
  if (!vis[id[SA::sa[x]]]) ++tot;
  ++vis[id[SA::sa[x]]];
}
inline void erase(int x) {
  if (!id[SA::sa[x]]) return;
  --vis[id[SA::sa[x]]];
  if (!vis[id[SA::sa[x]]]) --tot;
}
long long int ans[MAXN + 10];
int main() {
  Read(n), Read(k);
  m = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    int tlen = strlen(str + 1);
    for (int j = 1; j <= tlen; ++j) A[++m] = str[j] - 'a', id[m] = i;
    ed[i] = m;
    A[++m] = INF + i, id[m] = 0;
  }
  for (int i = 1; i <= m; ++i) t[i] = A[i];
  sort(t + 1, t + m + 1);
  int cnt = unique(t + 1, t + m + 1) - t - 1;
  for (int i = 1; i <= m; ++i) A[i] = lower_bound(t + 1, t + cnt + 1, A[i]) - t;
  SA::getsa(A, m, cnt);
  SA::getheight(A, m);
  init();
  for (int i = 1, j = 1; i <= m; ++i) {
    ins(i);
    erase(j++);
    while (j <= i && tot >= k) {
      insert(1, j, i, getmn(j, i), 1, m);
      erase(j++);
    }
    ins(--j);
    if (tot == k) {
      insert(1, j, i, getmn(j, i), 1, m);
    }
  }
  getall(1, 1, m, ans);
  for (int i = 1; i <= n; ++i) printf("%I64d%c", ans[i], i == n ? '\n' : ' ');
}
