#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
int n, k, m;
int pos[400007], P[400007];
int lcp[400007];
int s[400007];
vector<string> S;
int maxv[20][400007];
int first[400007];
int cnt[400007];
int type[400007];
int count(int i, int k) {
  if (k == 0) return m;
  int r = i;
  for (int j = 19; j >= 0; j--)
    if (maxv[j][r] >= k) r += (1 << j);
  int l = i;
  for (int j = 19; j >= 0; j--)
    if (l - (1 << j) >= 0 && maxv[j][l - (1 << j)] >= k) l -= (1 << j);
  return first[l] <= r ? ::k : 0;
}
int find_max_len(int i, int maxp) {
  int pocz = 0, kon = maxp, mid;
  while (pocz < kon) {
    mid = (pocz + kon + 1) / 2;
    if (count(i, mid) >= k)
      pocz = mid;
    else
      kon = mid - 1;
  }
  return pocz;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  int nxt = 0, nxt2 = 30;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    S.push_back(s);
    for (char c : s) {
      ::s[nxt] = pos[nxt] = c - 'a' + 1;
      nxt++;
    }
    ::s[nxt] = pos[nxt] = nxt2++;
    nxt++;
  }
  int m = nxt;
  for (int j = 1; j < m; j <<= 1) {
    vector<pair<ii, int> > hlp(m);
    for (int i = 0; i < m; i++) hlp[i] = {{pos[i], pos[i + j]}, i};
    sort(hlp.begin(), hlp.end());
    int k = 0;
    for (int i = 0; i < m; i++) {
      if (i > 0 && hlp[i].first != hlp[i - 1].first) k++;
      pos[hlp[i].second] = k;
    }
  }
  for (int i = 0; i < m; i++) P[pos[i]] = i;
  int t = 0;
  for (int i = 0; i + 1 < m; i++) {
    while (s[i + t] == s[P[pos[i] + 1] + t]) t++;
    lcp[pos[i]] = t;
    t = max(0, t - 1);
  }
  for (int i = 0; i < m; i++) maxv[0][i] = lcp[i];
  for (int k = 1; k < 20; k++)
    for (int i = 0; i < m; i++)
      maxv[k][i] =
          min(maxv[k - 1][i],
              i + (1 << (k - 1)) < m ? maxv[k - 1][i + (1 << (k - 1))] : 0);
  nxt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < S[i].size(); j++) type[pos[nxt + j]] = i;
    type[pos[nxt + S[i].size()]] = -1;
    nxt += S[i].size() + 1;
  }
  int j = -1;
  int diff = 0;
  for (int i = 0; i < m; i++) {
    j = max(j, i - 1);
    while (j + 1 < m && diff < k) {
      j++;
      if (type[j] >= 0) {
        cnt[type[j]]++;
        if (cnt[type[j]] == 1) diff++;
      }
    }
    if (diff == k)
      first[i] = j;
    else
      first[i] = m;
    if (type[i] >= 0) {
      cnt[type[i]]--;
      if (cnt[type[i]] == 0) diff--;
    }
  }
  int i = 0;
  for (string s : S) {
    ll cnt = 0;
    for (int j = 0; j < s.size(); j++) {
      cnt += find_max_len(pos[i + j], s.size() - j);
    }
    i += s.size() + 1;
    printf("%lld ", cnt);
  }
  printf("\n");
  return 0;
}
