#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << '(' << p.first << "," << p.second << ')';
}
int n, kk;
const int LEN = 400005;
vector<int> g[LEN];
int sub[LEN];
struct SA {
  struct state {
    int len, link;
    map<int, int> next;
  };
  state st[LEN];
  int sz, last;
  int cnt[LEN];
  int len[LEN];
  void SA_make() {
    sz = 0;
    st[0].len = 0, st[0].link = -1;
    ++sz;
    last = 0;
  }
  SA() { SA_make(); }
  void add(int c, int i, int l) {
    int new_n = sz++;
    st[new_n].len = st[last].len + 1;
    int pt = last;
    while (pt != -1 && !st[pt].next.count(c)) {
      st[pt].next[c] = new_n;
      pt = st[pt].link;
    }
    if (pt == -1) {
      st[new_n].link = 0;
    } else {
      int q_st = st[pt].next[c];
      if (st[q_st].len == st[pt].len + 1)
        st[new_n].link = q_st;
      else {
        int clone = sz++;
        st[clone] = st[q_st];
        st[clone].len = st[pt].len + 1;
        st[q_st].link = st[new_n].link = clone;
        while (pt != -1 && st[pt].next[c] == q_st) {
          st[pt].next[c] = clone;
          pt = st[pt].link;
        }
      }
    }
    last = new_n;
    cnt[last] = i;
    len[last] = l;
  }
  int minlen(int u) {
    if (u == 0) return 0;
    return st[st[u].link].len + 1;
  }
  void buildCount() {
    vector<int> v;
    for (int i = 1; i < sz; ++i) v.push_back(i);
    sort(v.begin(), v.end(),
         [&](int x, int y) { return st[x].len > st[y].len; });
    for (int i = 0; i < sz - 1; ++i) {
      ++sub[v[i]];
      sub[st[v[i]].link] += sub[v[i]];
      g[st[v[i]].link].push_back(v[i]);
      if (len[v[i]]) len[st[v[i]].link] = len[v[i]];
    }
  }
} sa;
long long ans[LEN / 2];
int cnt[LEN / 2];
vector<int> vec[LEN];
int Ans = 0;
int vis[LEN];
inline void add(int x) {
  x = sa.cnt[x];
  if (x == 0) return;
  if (cnt[x] == 0) ++Ans;
  ++cnt[x];
}
inline void del(int x) {
  x = sa.cnt[x];
  if (x == 0) return;
  if (cnt[x] == 1) --Ans;
  --cnt[x];
}
void dfs(int u, bool keep) {
  int mx = -1, bc = -1;
  for (auto j : g[u]) {
    if (sub[j] > mx) mx = sub[j], bc = j;
  }
  for (int j : g[u])
    if (j != bc) dfs(j, 0);
  if (bc != -1) {
    dfs(bc, 1), swap(vec[bc], vec[u]);
  }
  vec[u].push_back(u);
  add(u);
  for (int j : g[u])
    if (j != bc)
      for (auto k : vec[j]) add(k), vec[u].push_back(k);
  if (Ans >= kk) {
    int x = min(sa.st[u].len, sa.len[u]);
    if (sa.minlen(u) <= x || sa.len[u] == 0) {
      vis[u] += x - sa.minlen(u) + 1;
    }
  }
  if (!keep) {
    for (auto j : vec[u]) {
      del(j);
    }
  }
}
void dfs2(int u, long long val) {
  if (u) val += vis[u];
  if (sa.cnt[u]) ans[sa.cnt[u]] += val;
  for (auto j : g[u]) dfs2(j, val);
}
int _runtimeTerror_() {
  cin >> n >> kk;
  int nx = 1e6;
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < (long long)s.size(); ++j) sa.add(s[j] - 'a', i, j + 1);
    sa.add(nx++, i, 0);
  }
  sa.buildCount();
  dfs(0, 1);
  dfs2(0, 0);
  for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
  cout << "\n";
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) _runtimeTerror_();
  return 0;
}
