#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e60;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
inline char mygetchar() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
template <typename T>
void chkmax(T &x, const T &y) {
  if (y > x) x = y;
  return;
}
template <typename T>
void chkmin(T &x, const T &y) {
  if (y < x) x = y;
  return;
}
void TZL();
void RANK1();
int main() {
  TZL();
  RANK1();
  return 0;
}
const int N = 1e5 + 100;
int *s[N];
int apr[N], tot, clk;
struct sam {
  struct edge {
    sam *to;
    edge *next;
  };
  set<int> all;
  sam *ch[27], *par, *son;
  int id, cnt, mx, siz;
  int dfn, End;
  edge *head;
  bool vis;
  sam() {
    for (int i = 0, _end_ = (27); i < _end_; ++i) ch[i] = 0;
    par = 0;
    id = -1;
    cnt = mx = 0;
    head = 0;
    vis = 0;
    all.clear();
  }
  void cpy(sam *x) {
    memcpy((ch), (x->ch), sizeof((x->ch)));
    par = x->par;
    return;
  }
  void expand(int e, int ID = -1);
  void add_edge(sam *u) {
    edge *e = new edge;
    e->next = head;
    e->to = u;
    head = e;
    return;
  }
  void make_graph() {
    if (vis) return;
    vis = 1;
    if (par) par->add_edge(this);
    for (int i = 0, _end_ = (27); i < _end_; ++i)
      if (ch[i]) ch[i]->make_graph();
    return;
  }
  void pre_dfs();
  void dfs(bool keep = 0);
} * root, *last;
sam **rdfn;
void sam::expand(int e, int ID) {
  sam *p = last, *np = new sam;
  np->mx = p->mx + 1;
  np->id = ID;
  while (p && !p->ch[e]) p->ch[e] = np, p = p->par;
  if (!p)
    np->par = root;
  else {
    sam *q = p->ch[e];
    if (q->mx == p->mx + 1)
      np->par = q;
    else {
      sam *nq = new sam;
      nq->cpy(q);
      nq->mx = p->mx + 1;
      q->par = np->par = nq;
      while (p && p->ch[e] == q) p->ch[e] = nq, p = p->par;
    }
  }
  last = np;
  return;
}
void sam::pre_dfs() {
  int hs = 0;
  siz = 1;
  son = 0;
  dfn = (++clk);
  for (auto e = head; e; e = e->next) {
    e->to->pre_dfs();
    siz += e->to->siz;
    if (e->to->siz > hs) {
      hs = e->to->siz;
      son = e->to;
    }
  }
  End = clk;
  return;
}
void sam::dfs(bool keep) {
  for (auto e = head; e; e = e->next) e->to->dfs();
  if (son) {
    all = son->all;
    for (auto e = head; e; e = e->next)
      if (e->to != son) all.insert(e->to->all.begin(), e->to->all.end());
  }
  if (~id) all.insert(id);
  cnt = (int)all.size();
  return;
}
int n, k;
void TZL() {
  root = new sam;
  last = root;
  scf(n, k);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    static char t[N];
    scanf("%s", t);
    int l = strlen(t);
    s[i] = new int[l + 1];
    for (int j = 0, _end_ = (l); j < _end_; ++j)
      last->expand(s[i][j] = (t[j] - 'a'), i);
    last->expand(s[i][l] = 26);
  }
  root->make_graph();
  root->pre_dfs();
  rdfn = new sam *[clk + 10];
  root->dfs();
  return;
}
void RANK1() {
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    long long ans = 0;
    sam *cur = root;
    int matched = 0;
    for (int j = 0; s[i][j] < 26; ++j) {
      int &e = s[i][j];
      while (cur && !cur->ch[e]) cur = cur->par, matched = cur ? cur->mx : 0;
      if (!cur) {
        cur = root;
        matched = 0;
      } else {
        cur = cur->ch[e];
        ++matched;
      }
      while (cur && cur->cnt < k) cur = cur->par, matched = cur ? cur->mx : 0;
      ans += (long long)matched;
    }
    printf("%lld ", ans);
  }
  return;
}
