#include <bits/stdc++.h>
using namespace std;
int wa[201005], wb[201005], wv[201005], WS[201005];
int cmp(int *r, int a, int b, int k) {
  return r[a] == r[b] && r[a + k] == r[b + k];
}
void da(int *r, int *sa, int n, int m) {
  int i, j, p, *x = wa, *y = wb, *t;
  for (i = 0; i < m; i++) WS[i] = 0;
  for (i = 0; i < n; i++) WS[x[i] = r[i]]++;
  for (i = 1; i < m; i++) WS[i] += WS[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--WS[x[i]]] = i;
  for (j = 1, p = 1; p < n; j *= 2, m = p) {
    for (p = 0, i = n - j; i < n; i++) y[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    for (i = 0; i < n; i++) wv[i] = x[y[i]];
    for (i = 0; i < m; i++) WS[i] = 0;
    for (i = 0; i < n; i++) WS[wv[i]]++;
    for (i = 1; i < m; i++) WS[i] += WS[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--WS[wv[i]]] = y[i];
    for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; i++) {
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
    }
  }
  return;
}
int rk[201005], height[201005];
void calheight(int *r, int *sa, int n) {
  int i, j, k = 0;
  for (i = 1; i <= n; i++) rk[sa[i]] = i;
  for (i = 0; i < n; height[rk[i++]] = k) {
    for (k ? k-- : 0, j = sa[rk[i] - 1]; r[i + k] == r[j + k]; k++)
      ;
  }
  return;
}
int arr[201005], SA[201005], q[201005], bg[201005], LV[201005], pre[201005];
long long C[2][201005], ret[201005];
int lowbit(int x) { return x & (-x); }
void up(int x, int v, int id) {
  while (x < 201005) {
    C[id][x] += v;
    x += lowbit(x);
  }
}
long long getsum(int x, int id) {
  long long r = 0;
  while (x > 0) {
    r += C[id][x];
    x -= lowbit(x);
  }
  return r;
}
char str[201005];
int main() {
  int m, n, i, k;
  scanf("%d%d", &m, &k);
  {
    memset(pre, -1, sizeof(pre));
    n = 0;
    for (i = 0; i < m; i++) {
      scanf("%s", str);
      int len = strlen(str), j;
      for (j = 0; j < len; j++) {
        arr[n + j] = str[j];
        LV[n + j] = len - j;
        bg[n + j] = i;
      }
      arr[n + len] = 'z' + i % 300 + 1;
      bg[n + len] = -1;
      n += len + 1;
    }
    arr[n] = 0;
    bg[n] = -1;
    da(arr, SA, n + 1, 500);
    calheight(arr, SA, n);
    height[n + 1] = 0;
    int t = 0, w = 1;
    q[0] = n + 1;
    for (i = n; i >= 0; i--) {
      if (bg[SA[i]] != -1) {
        if (pre[bg[SA[i]]] != -1) up(pre[bg[SA[i]]], -1, 0);
        pre[bg[SA[i]]] = i + 1;
        up(i + 1, 1, 0);
      }
      int len = LV[SA[i]];
      while (t < w && height[q[w - 1]] >= height[i]) {
        if (len > height[q[w - 1]]) {
          long long tmp = getsum(q[w - 1], 0) - getsum(i, 0);
          if (tmp >= k) {
            up(q[w - 1] + 1, -(len - height[q[w - 1]]), 1);
            up(i + 1, (len - height[q[w - 1]]), 1);
          }
        }
        if (len > height[q[w - 1]]) len = height[q[w - 1]];
        w--;
      }
      if (t < w && len > height[q[w - 1]] && len > height[i]) {
        long long tmp = getsum(q[w - 1], 0) - getsum(i, 0);
        if (tmp >= k) {
          up(q[w - 1] + 1, -(len - height[i]), 1);
          up(i + 1, (len - height[i]), 1);
        }
      }
      q[w++] = i;
    }
  }
  for (i = 0; i <= n; i++) {
    long long tmp = getsum(i + 1, 1);
    if (bg[SA[i]] != -1) ret[bg[SA[i]]] += tmp;
  }
  for (i = 0; i < m - 1; i++) printf("%I64d ", ret[i]);
  printf("%I64d\n", ret[i]);
  return 0;
}
