#include <bits/stdc++.h>
using namespace std;
long long a, b, c, sa[200001], id[200001], cnt[200001], rk[200001], rk1[200001],
    ht[200001], m[200001], cn, len, ans[200001], le[200001], s1[200001];
string s;
struct p {
  long long q, w, e;
};
struct pp {
  long long mi;
} l[1000001];
vector<p> qu;
deque<p> quu;
void SA() {
  len = a + 'z' + 1;
  for (int i = 1; i <= c; i++) {
    cnt[s1[i - 1]]++;
    rk[i] = s1[i - 1];
  }
  for (int i = 1; i <= len; i++) {
    cnt[i] += cnt[i - 1];
  }
  for (int i = c; i >= 1; i--) {
    sa[cnt[rk[i]]] = i;
    cnt[rk[i]]--;
  }
  for (int ii = 1;; ii <<= 1) {
    cn = 0;
    for (int i = c; i > c - ii; i--) {
      id[++cn] = i;
    }
    for (int i = 1; i <= c; i++) {
      if (sa[i] > ii) {
        id[++cn] = sa[i] - ii;
      }
    }
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= c; i++) {
      cnt[rk[id[i]]]++;
    }
    for (int i = 1; i <= len; i++) {
      cnt[i] += cnt[i - 1];
    }
    for (int i = c; i >= 1; i--) {
      sa[cnt[rk[id[i]]]] = id[i];
      cnt[rk[id[i]]]--;
    }
    memcpy(rk1, rk, sizeof(rk));
    cn = 0;
    for (int i = 1; i <= c; i++) {
      if (rk1[sa[i]] == rk1[sa[i - 1]] &&
          rk1[sa[i] + ii] == rk1[sa[i - 1] + ii]) {
        rk[sa[i]] = cn;
      } else
        rk[sa[i]] = ++cn;
    }
    len = cn;
    if (len == c) {
      break;
    }
  }
  for (int i = 1; i <= c; i++) {
    sa[rk[i]] = i;
  }
  cn = 0;
  for (int i = 1; i <= c; i++) {
    if (cn) {
      cn--;
    }
    while (s1[cn + i - 1] == s1[cn + sa[rk[i] - 1] - 1]) {
      cn++;
    }
    ht[rk[i]] = cn;
  }
}
void pushup(long long qq) { l[qq].mi = min(l[qq << 1].mi, l[qq << 1 | 1].mi); }
void build(long long x, long long ll, long long rr) {
  if (ll == rr) {
    l[x].mi = ht[ll];
    return;
  }
  long long mid = ((ll + rr) >> 1);
  build(x << 1, ll, mid);
  build(x << 1 | 1, mid + 1, rr);
  pushup(x);
}
long long query(long long x, long long ll, long long rr, long long qq,
                long long ww) {
  if (qq <= ll && rr <= ww) {
    return l[x].mi;
  }
  long long mid = ((ll + rr) >> 1);
  if (mid >= ww) {
    return query(x << 1, ll, mid, qq, ww);
  } else if (mid < qq) {
    return query(x << 1 | 1, mid + 1, rr, qq, ww);
  } else
    return min(query(x << 1, ll, mid, qq, ww),
               query(x << 1 | 1, mid + 1, rr, qq, ww));
}
int main() {
  scanf("%lld%lld", &a, &b);
  long long yy = 0;
  for (int i = 1; i <= a; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      s1[j + yy] = s[j] + a + 1;
      le[j + yy + 1] = s.size() - j;
      m[j + yy + 1] = i;
    }
    yy += s.size();
    s1[yy++] = i;
  }
  c = yy;
  SA();
  long long tt = 0;
  yy = 1;
  for (int i = 1; i <= c; i++) {
    if (m[sa[i]] == 0) ht[i] = 0x3f3f3f3f3f3f;
  }
  build(1, 1, c);
  yy = a + 1;
  memset(cnt, 0, sizeof(cnt));
  for (int i = a + 1; i <= c; i++) {
    cnt[m[sa[i]]]++;
    if (cnt[m[sa[i]]] == 1) {
      tt++;
    }
    while (tt >= b) {
      if (tt == b) {
        if (yy + 1 <= i)
          qu.push_back(p{yy, i, query(1, 1, c, yy + 1, i)});
        else
          qu.push_back(p{yy, i, le[sa[i]]});
      }
      if (cnt[m[sa[yy]]] == 1) {
        if (tt == b) break;
        tt--;
      }
      cnt[m[sa[yy]]]--;
      yy++;
    }
  }
  long long oo = 0;
  for (int i = 1; i <= c; i++) {
    if (m[sa[i]] == 0) continue;
    while (!quu.empty() && quu.front().w < i) {
      quu.pop_front();
    }
    while (oo < qu.size() && qu[oo].q <= i) {
      while (!quu.empty() && qu[oo].e > quu.back().e) {
        quu.pop_back();
      }
      quu.push_back(qu[oo]);
      oo++;
    }
    if (!quu.empty()) {
      ans[m[sa[i]]] += quu.front().e;
    }
  }
  for (int i = 1; i <= a; i++) {
    printf("%lld ", ans[i]);
  }
  return 0;
}
