#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct EXSAM_node {
  EXSAM_node *next[26], *pre;
  int step;
  int bel;
  int size;
  int visit;
  int cnt[3];
  map<int, int> cnt2;
  void clear() {
    pre = NULL;
    step = 0;
    size = 0;
    visit = 0;
    memset(next, 0, sizeof(next));
    memset(cnt, 0, sizeof(cnt));
  }
};
EXSAM_node EXSAM_Pool[N * 2];
EXSAM_node *EXpool[N * 2];
long d[N * 2];
struct EXSAM {
  EXSAM_node *root, *last;
  EXSAM_node *cur;
  void init() {
    cur = EXSAM_Pool;
    root = last = cur++;
    root->clear();
    root->visit = 0;
  }
  void Insert(int w, int i) {
    EXSAM_node *p = last;
    if (p->next[w] && p->next[w]->step == p->step + 1) {
      last = p->next[w];
      last->cnt2[i] = 1;
      return;
    }
    EXSAM_node *np = cur++;
    np->clear();
    np->step = p->step + 1;
    while (p && !p->next[w]) {
      p->next[w] = np, p = p->pre;
    }
    if (p == 0)
      np->pre = root;
    else {
      EXSAM_node *q = p->next[w];
      if (p->step + 1 == q->step)
        np->pre = q;
      else {
        EXSAM_node *nq = cur++;
        nq->clear();
        nq->step = p->step + 1;
        memcpy(nq->next, q->next, sizeof(q->next));
        nq->pre = q->pre;
        q->pre = nq;
        np->pre = nq;
        while (p && p->next[w] == q) {
          p->next[w] = nq, p = p->pre;
        }
      }
    }
    last = np;
    last->cnt2[i] = 1;
  }
  void topo() {
    int cnt = cur - EXSAM_Pool;
    int maxVal = 0;
    memset(d, 0, sizeof(d));
    for (int i = 1; i < cnt; i++) {
      maxVal = max(maxVal, EXSAM_Pool[i].step), d[EXSAM_Pool[i].step]++;
    }
    for (int i = 1; i <= maxVal; i++) d[i] += d[i - 1];
    for (int i = 1; i < cnt; i++)
      EXpool[d[EXSAM_Pool[i].step]--] = &EXSAM_Pool[i];
    EXpool[0] = root;
  }
};
long long ans[110000];
int main() {
  ios::sync_with_stdio(false);
  EXSAM part;
  int P, K;
  cin >> P >> K;
  string a, b, c;
  cin.tie(0);
  cout.tie(0);
  part.init();
  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < P; ++i) {
    cin >> a;
    for (auto &s : a) part.Insert(s - 'a', i);
    part.last = part.root;
  }
  part.topo();
  int cnt = part.cur - EXSAM_Pool;
  for (int i = cnt - 1; i >= 1; i--)
    for (auto &s : EXpool[i]->cnt2) EXpool[i]->pre->cnt2[s.first] += s.second;
  for (int i = cnt - 1; i >= 1; i--) {
    if (EXpool[i]->cnt2.size() >= K)
      for (auto &s : EXpool[i]->cnt2)
        ans[s.first] += (EXpool[i]->step - EXpool[i]->pre->step) * s.second;
  }
  for (int i = 0; i < P; ++i) cout << ans[i] << " ";
  return 0;
}
