#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
struct SuffixAutomaton {
  struct state {
    int len, link, idx;
    map<char, int> transitions;
  };
  int n, last, sz;
  vector<state> states;
  vector<bool> terminal;
  SuffixAutomaton(int _n) {
    n = _n, sz = 1, last = 0;
    terminal.resize(2 * n);
    states.resize(2 * n);
    states[0].len = 0, states[0].link = -1;
  }
  void extend(char c, int idx) {
    int cur = sz++;
    states[cur].len = states[last].len + 1;
    states[cur].idx = idx;
    int p;
    for (p = last; p != -1 && !states[p].transitions.count(c);
         p = states[p].link) {
      states[p].transitions[c] = cur;
    }
    if (p == -1)
      states[cur].link = 0;
    else {
      int q = states[p].transitions[c];
      if (states[p].len + 1 == states[q].len)
        states[cur].link = q;
      else {
        int clone = sz++;
        states[clone].len = states[p].len + 1;
        states[clone].transitions = states[q].transitions;
        states[clone].link = states[q].link;
        for (; p != -1 && states[p].transitions[c] == q; p = states[p].link) {
          states[p].transitions[c] = clone;
        }
        states[q].link = states[cur].link = clone;
      }
    }
    last = cur;
  }
  void markTerminals() {
    int p = last;
    while (p) {
      terminal[p] = true;
      p = states[p].link;
    }
  }
};
SuffixAutomaton SAM(N);
vector<int> g[N];
string s[N];
int cnt[N];
set<int> st[N];
void dfs(int u) {
  int mx = u;
  for (int v : g[u]) {
    dfs(v);
    if ((int)st[v].size() > (int)st[mx].size()) mx = v;
  }
  swap(st[u], st[mx]);
  st[mx].clear();
  if (SAM.states[u].idx) st[u].insert(SAM.states[u].idx);
  for (int v : g[u]) {
    if (v == mx) continue;
    for (int x : st[v]) st[u].insert(x);
    st[v].clear();
  }
  cnt[u] = st[u].size();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    SAM.extend('@', 0);
    for (char c : s[i]) SAM.extend(c, i);
  }
  for (int i = 1; i < SAM.sz; i++) {
    g[SAM.states[i].link].push_back(i);
  }
  dfs(0);
  for (int i = 1; i <= n; i++) {
    int x = 0;
    long long ans = 0, len = 0;
    for (int j = 0; j < (int)s[i].size(); j++) {
      while (x && !SAM.states[x].transitions.count(s[i][j])) {
        x = SAM.states[x].link;
        len = SAM.states[x].len;
      }
      x = SAM.states[x].transitions[s[i][j]];
      len++;
      while (x && cnt[x] < k) {
        x = SAM.states[x].link;
        len = SAM.states[x].len;
      }
      ans += len;
    }
    cout << ans << " ";
  }
  return 0;
}
