#include <bits/stdc++.h>
using namespace std;
const int kinds = 256;
char str[200005];
int K, buc[200005], r[200005], sa[200005], X[200005], Y[200005], high[200005];
bool cmp(int* r, int a, int b, int x) {
  return (r[a] == r[b] && r[a + x] == r[b + x]);
}
void suffix_array_DA(int n, int m) {
  int *x = X, *y = Y, i, j, k = 0, l;
  memset(buc, 0, sizeof(buc));
  for (i = 0; i < n; i++) buc[x[i] = str[i]]++;
  for (i = 1; i < m; i++) buc[i] += buc[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--buc[x[i]]] = i;
  for (l = 1, j = 1; j < n; m = j, l <<= 1) {
    j = 0;
    for (i = n - l; i < n; i++) y[j++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= l) y[j++] = sa[i] - l;
    for (i = 0; i < m; i++) buc[i] = 0;
    for (i = 0; i < n; i++) buc[x[y[i]]]++;
    for (i = 1; i < m; i++) buc[i] += buc[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--buc[x[y[i]]]] = y[i];
    for (swap(x, y), x[sa[0]] = 0, i = 1, j = 1; i < n; i++)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], l) ? j - 1 : j++;
  }
  for (i = 1; i < n; i++) r[sa[i]] = i;
  for (i = 0; i < n - 1; high[r[i++]] = k)
    for (k ? k-- : 0, j = sa[r[i] - 1]; str[i + k] == str[j + k]; k++)
      ;
}
vector<int> suffix_array_construction(string s) {
  int n = s.size();
  for (int i = 0; i < n; i++) str[i] = s[i];
  str[n] = '\0';
  suffix_array_DA(n + 1, kinds);
  vector<int> saa;
  for (int i = 1; i <= n; i++) saa.push_back(sa[i]);
  return saa;
}
vector<int> lcp_construction(string const& s, vector<int> const& p) {
  int n = s.size();
  vector<int> rank(n, 0);
  for (int i = 0; i < n; i++) rank[p[i]] = i;
  int k = 0;
  vector<int> lcp(n - 1, 0);
  for (int i = 0; i < n; i++) {
    if (rank[i] == n - 1) {
      k = 0;
      continue;
    }
    int j = p[rank[i] + 1];
    while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;
    lcp[rank[i]] = k;
    if (k) k--;
  }
  return lcp;
}
int n, k;
vector<int> suffar, LCP;
int pos_in_sa[200005];
struct st {
  int id, len, nex, mch;
} ara[200005];
int fre[200005];
int pwr[200005], tab[200005][25], par[200005][25];
void build_sp(int n) {
  int p = 0;
  for (int i = 1; i < n; i *= 2) pwr[i] = p, p++;
  for (int i = 1; i < n; i++) pwr[i] = (pwr[i] == 0) ? pwr[i - 1] : pwr[i];
  for (int j = 0; j < 20; j++)
    for (int i = 0; i < n; i++)
      if (j == 0)
        par[i][j] = i;
      else
        par[i][j] = par[par[i][j - 1] + 1][j - 1];
  for (int i = 0; i < n; i++) tab[i][0] = ara[i].mch;
  for (int j = 1; j < 20; j++)
    for (int i = 0; i < n; i++)
      tab[i][j] = min(tab[i][j - 1], tab[par[i][j - 1] + 1][j - 1]);
}
int spquery(int i, int j) {
  if (i > j) return 0;
  int lgd = pwr[j - i + 1];
  int d = (1 << lgd);
  int l = i, r = j - d + 1;
  int ret = min(tab[l][lgd], tab[r][lgd]);
  return ret;
}
int getl(int pos, int len) {
  if (pos == 0) return pos;
  if (ara[pos - 1].mch < len) return pos;
  int l = 0, r = pos - 1;
  int ret = pos - 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (spquery(mid, pos - 1) >= len) {
      ret = min(ret, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ret;
}
int getr(int pos, int len) {
  if (pos == suffar.size() - 1) return pos;
  if (ara[pos].mch < len) return pos;
  int l = pos + 1, r = suffar.size() - 1;
  int ret = pos;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (spquery(pos, mid - 1) >= len) {
      ret = max(ret, mid);
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ret;
}
int f2(int pos, int len) {
  int l = getl(pos, len);
  int r = getr(pos, len);
  if (ara[l].nex == -1) return 0;
  if (ara[l].nex > r) return 0;
  return 1;
}
int f1(int pos) {
  int l = 1, r = ara[pos].len;
  int ret = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (f2(pos, mid)) {
      ret = max(ret, mid);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ret;
}
long long ans[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> k;
  string s, A;
  for (int i = 0; i < n; i++) cin >> s, A += s + '#';
  suffar = suffix_array_construction(A);
  LCP = lcp_construction(A, suffar);
  int j = 0;
  for (int i : suffar) pos_in_sa[i] = j++;
  int hash_cnt = 0, len = 0;
  LCP.push_back(0);
  for (int i = A.size() - 1; i >= 0; i--) {
    len++;
    if (A[i] == '#')
      hash_cnt++, len = 0;
    else {
      ara[pos_in_sa[i]].id = (n - hash_cnt);
      ara[pos_in_sa[i]].len = len;
      ara[pos_in_sa[i]].mch = min(LCP[pos_in_sa[i]], len);
    }
  }
  int i = n, ct = 0;
  j = n;
  while (i < suffar.size()) {
    while (ct < k and j < A.size()) {
      fre[ara[j].id]++;
      if (fre[ara[j].id] == 1) ct++;
      j++;
    }
    if (ct >= k)
      ara[i].nex = j - 1;
    else
      ara[i].nex = -1;
    fre[ara[i].id]--;
    if (fre[ara[i].id] == 0) ct--;
    i++;
  }
  int N = suffar.size();
  build_sp(N);
  for (int i = n; i < N; i++) {
    int ret = f1(i);
    ans[ara[i].id] += ret;
  }
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
}
