#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
const int N = 1e6 + 10;
char tmp[N];
int s[N];
int sa[N], rk[N * 2], oldrk[N * 2], k, tot;
bool cmp(int x, int y, int w) {
  return oldrk[x] == oldrk[y] && oldrk[x + w] == oldrk[y + w];
}
void GetSA(int* s, int n) {
  for (int i = (1); i <= (n); ++i) sa[i] = i, rk[i] = s[i];
  for (int w = 1; w < n; w <<= 1) {
    std::sort(sa + 1, sa + 1 + n, [&](int x, int y) {
      return rk[x] != rk[y] ? rk[x] < rk[y] : rk[x + w] < rk[y + w];
    });
    std::memcpy(oldrk, rk, sizeof(rk));
    for (int p = 0, i = 1; i <= n; ++i) {
      rk[sa[i]] = cmp(sa[i], sa[i - 1], w) ? p : ++p;
    }
  }
}
int height[N], belong[N];
void GetHeight(int* s, int n) {
  int k = 0;
  for (int i = (1); i <= (n); ++i) {
    if (rk[i] == 1)
      k = 0;
    else {
      if (k > 0) k--;
      int j = sa[rk[i] - 1];
      while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) ++k;
    }
    height[rk[i]] = k;
  }
}
int a[N], order[N];
std::map<int, int> buk[N];
int fa[N];
int getf(int x) { return x == fa[x] ? x : (fa[x] = getf(fa[x])); }
long long ans[N];
void upd(int x, int r) {
  for (auto i : buk[x]) {
    ans[i.first] += 1ll * i.second * r;
  }
}
void merge(int x, int y, int r) {
  x = getf(x);
  y = getf(y);
  if (x == y) return;
  if (buk[x].size() >= k && buk[y].size() >= k)
    ;
  else if (buk[x].size() < k && buk[y].size() < k) {
    if (buk[x].size() < buk[y].size()) std::swap(x, y);
    for (auto i : buk[y]) buk[x][i.first] += i.second;
    if (buk[x].size() >= k) upd(x, r);
  } else {
    if (buk[x].size() < k) std::swap(x, y);
    upd(y, r);
  }
  fa[y] = x;
}
void print(int i) {
  for (; i <= tot; ++i) {
    if (s[i] <= 25)
      cerr << char(s[i] + 'a');
    else
      cout << '#';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  int n;
  cin >> n >> k;
  for (int i = (1); i <= (n); ++i) {
    cin >> tmp;
    for (int j = 0; tmp[j]; ++j) {
      s[++tot] = tmp[j] - 'a';
    }
    s[++tot] = i + 25;
    a[i] = tot;
  }
  GetSA(s, tot);
  GetHeight(s, tot);
  std::iota(order + 1, order + 1 + tot, 1);
  for (int i = (1); i <= (tot); ++i) {
    belong[i] = std::lower_bound(a + 1, a + 1 + n, i) - a;
    fa[i] = i;
    buk[i][belong[i]] = 1;
    if (buk[i].size() >= k) upd(i, a[belong[i]] - i);
  }
  std::sort(order + 2, order + 1 + tot,
            [&](int x, int y) { return height[x] > height[y]; });
  for (int i = (2); i <= (tot); ++i) {
    if (height[order[i]] == 0) break;
    merge(sa[order[i] - 1], sa[order[i]], height[order[i]]);
  }
  for (int i = (1); i <= (n); ++i) cout << ans[i] << ' ';
  return 0;
}
