#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::ios;
using std::max;
using std::sort;
using std::string;
using std::vector;
const int MAXN = 100005, MAX_SZ = 26;
int n, k, sam_cnt;
int appear_cnt[MAXN << 1];
string s[MAXN];
vector<int> id[MAXN << 1];
class BIT {
 private:
  int c[MAXN << 1];
  int lowbit(int x) { return x & -x; }
  int qry(int r) {
    int ret = 0;
    for (; r; r -= lowbit(r)) ret += c[r];
    return ret;
  }
  void add(int l, int x) {
    for (; l <= sam_cnt; l += lowbit(l)) c[l] += x;
  }

 public:
  void del(int l) { add(l, -1); }
  void ist(int l) { add(l, 1); }
  int qry(int l, int r) { return qry(r) - qry(l - 1); }
};
class dfn_subT {
 private:
  int he[MAXN << 1];
  int dfn[MAXN << 1], lp[MAXN << 1], rp[MAXN << 1];
  struct line {
    int to, nex;
  } ed[MAXN << 1];
  struct query {
    int id, lp, rp;
    static bool cmp_rp(const query &a, const query &b) { return a.rp < b.rp; }
  } qry[MAXN << 1];
  BIT ta;
  void DFS(int u) {
    dfn[++dfn[0]] = u;
    lp[u] = dfn[0];
    for (int i = he[u]; i; i = ed[i].nex) DFS(ed[i].to);
    rp[u] = dfn[0];
  }

 public:
  void addE(int u, int v) {
    static int cnt;
    ed[++cnt] = (line){v, he[u]};
    he[u] = cnt;
  }
  void init() { DFS(1); }
  void add_qry(int u) { qry[u] = (query){u, lp[u], rp[u]}; }
  void solve() {
    static int last_pos[MAXN];
    sort(qry + 1, qry + sam_cnt + 1, query::cmp_rp);
    for (int i = 1, k = 1, u; i <= dfn[0]; ++i) {
      u = dfn[i];
      for (int j = 0, id, lim = ::id[u].size(); j < lim; ++j) {
        id = ::id[u][j];
        if (last_pos[id]) ta.del(last_pos[id]);
        ta.ist(i);
        last_pos[id] = i;
      }
      for (; qry[k].rp == i; ++k)
        appear_cnt[qry[k].id] = ta.qry(qry[k].lp, qry[k].rp);
    }
    appear_cnt[1] = 0;
  }
};
class SAM {
 private:
  int rt, last, cnt, maxl;
  int topo[MAXN << 1];
  struct node {
    int maxl, fa;
    long long sub_str_sz;
    int c[MAX_SZ];
    int &operator[](int i) { return c[i]; }
  } d[MAXN << 1];
  dfn_subT parent_T;
  int chr_idx(char c) { return c - 'a'; }
  int new_nd(int maxl) {
    d[++cnt].maxl = maxl;
    return cnt;
  }
  int copy_nd(int u) {
    d[++cnt] = d[u];
    return cnt;
  }
  void extend(int c) {
    int cur = last, u = d[cur][c];
    if (u) {
      if (d[u].maxl == d[cur].maxl + 1)
        last = u;
      else {
        int v = copy_nd(u);
        d[v].maxl = d[cur].maxl + 1;
        d[u].fa = v;
        while (d[cur][c] == u) {
          d[cur][c] = v;
          cur = d[cur].fa;
        }
        last = v;
      }
    } else {
      u = new_nd(d[cur].maxl + 1);
      while (cur && !d[cur][c]) {
        d[cur][c] = u;
        cur = d[cur].fa;
      }
      if (!cur)
        d[u].fa = rt;
      else {
        int v = d[cur][c];
        if (d[v].maxl == d[cur].maxl + 1)
          d[u].fa = v;
        else {
          int w = copy_nd(v);
          d[w].maxl = d[cur].maxl + 1;
          d[v].fa = d[u].fa = w;
          while (d[cur][c] == v) {
            d[cur][c] = w;
            cur = d[cur].fa;
          }
        }
      }
      last = u;
    }
    maxl = max(maxl, d[last].maxl);
  }
  void topo_sort() {
    static int buc[MAXN];
    for (int i = 1; i <= cnt; ++i) ++buc[d[i].maxl];
    for (int i = 1; i <= maxl; ++i) buc[i] += buc[i - 1];
    for (int i = 1; i <= cnt; ++i) topo[buc[d[i].maxl]--] = i;
  }

 public:
  SAM() { rt = last = cnt = 1; }
  void ist(int id, const char T[]) {
    last = rt;
    for (int i = 0, len = strlen(T); i < len; ++i) {
      extend(chr_idx(T[i]));
      ::id[last].push_back(id);
    }
  }
  void build_T() {
    sam_cnt = cnt;
    for (int i = 2; i <= cnt; ++i) parent_T.addE(d[i].fa, i);
    parent_T.init();
  }
  void prepare() {
    for (int i = 1; i <= cnt; ++i) parent_T.add_qry(i);
    parent_T.solve();
    topo_sort();
    for (int i = 2, u, fa; i <= cnt; ++i) {
      u = topo[i], fa = d[u].fa;
      d[u].sub_str_sz += d[fa].sub_str_sz;
      if (appear_cnt[u] >= k) d[u].sub_str_sz += d[u].maxl - d[fa].maxl;
    }
  }
  long long cal(const char P[]) {
    long long ret = 0;
    for (int i = 0, cur = rt, len = strlen(P); i < len; ++i) {
      cur = d[cur][chr_idx(P[i])];
      ret += d[cur].sub_str_sz;
    }
    return ret;
  }
} sam;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    sam.ist(i, s[i].c_str());
  }
  sam.build_T();
  sam.prepare();
  for (int i = 1; i <= n; ++i) cout << sam.cal(s[i].c_str()) << ' ';
  return 0;
}
