#include <bits/stdc++.h>
using namespace std;
namespace SuffixArray {
const long long N = 2e5 + 1e4;
long long n, k, R, num;
vector<long long> s, v;
long long K[N], cn[N], sa[N], lcp[N], rmq[N][19], Res[N], maxSize[N];
unsigned long long h[N], po[N];
const unsigned long long BASE = 1e9 + 7;
inline bool cmp(long long i, long long j) {
  long long l = 0, r = min(n - i, n - j), m;
  while (l <= r) {
    m = (l + r) >> 1;
    if ((h[i] - h[i + m] * po[m]) == (h[j] - h[j + m] * po[m]))
      l = m + 1;
    else
      r = m - 1;
  }
  R = r;
  return s[i + r] < s[j + r];
}
void build() {
  cin >> num >> k;
  for (long long numi = 1; numi <= num; numi++) {
    string teS;
    cin >> teS;
    for (long long i = 0; i < teS.size(); i++) {
      s.push_back(teS[i]);
      v.push_back(numi);
      maxSize[s.size() - 1] = teS.size() - i;
    }
    n += teS.size() + 1;
    s.push_back(137LL + numi);
    v.push_back(numi);
  }
  po[0] = 1;
  for (long long i = 1; i < n; i++) po[i] = po[i - 1] * BASE;
  h[n] = 0;
  for (long long i = n - 1; i >= 0; i--) {
    h[i] = h[i + 1] * BASE + s[i];
    sa[i] = i;
  }
  stable_sort(sa, sa + n, cmp);
  lcp[0] = 0;
  for (long long i = 1; i < n - 1; i++) {
    cmp(sa[i], sa[i - 1]);
    lcp[i] = R;
  }
  for (long long i = 0; i < n - 1; i++) rmq[i][0] = min(lcp[i], lcp[i + 1]);
  for (long long j = 1; j < 17; j++)
    for (long long i = 0; i < n; i++)
      if (i + (1 << j) < n) {
        rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << j - 1)][j - 1]);
      }
  set<long long> se;
  long long j = 0, p = n + 1;
  for (long long i = 0; i < n; i++) K[i] = -1;
  for (long long i = 0; i < n; i++) {
    cn[v[sa[i]]]++;
    se.insert(v[sa[i]]);
    if (se.size() == k) {
      while (se.size() == k) {
        if (cn[v[sa[j]]] == 1) break;
        cn[v[sa[j]]]--;
        j++;
      }
      K[i] = j;
      p = i + 1;
      break;
    }
  }
  for (; p < n; p++) {
    cn[v[sa[p]]]++;
    se.insert(v[sa[p]]);
    while (se.size() >= k) {
      if (cn[v[sa[j]]] == 1 && se.size() == k) break;
      cn[v[sa[j]]]--;
      if (cn[v[sa[j]]] == 0) se.erase(se.find(v[sa[j]]));
      j++;
    }
    K[p] = j;
  }
}
long long RMQL(long long t, long long m) {
  for (long long j = 17; j >= 0; j--) {
    if (t - (1 << j) >= 0 && rmq[t - (1 << j)][j] >= m) {
      t -= (1 << j);
    }
  }
  if (lcp[t] >= m) t--;
  return t;
}
long long RMQR(long long t, long long m) {
  if (lcp[t] < m) t++;
  if (lcp[t] < m) {
    t--;
    return t;
  }
  for (long long j = 17; j >= 0; j--) {
    if (t + (1 << j) < n && rmq[t][j] >= m) {
      t += (1 << j);
    }
  }
  return t;
}
bool F(long long t, long long m) {
  long long l = RMQL(t, m);
  long long r = RMQR(t, m);
  return (K[r] >= l);
}
void proc() {
  for (long long i = 0; i < n; i++) {
    long long t = i;
    long long l = 1, r = maxSize[sa[i]], m;
    while (l <= r) {
      m = (l + r) >> 1;
      if (F(t, m))
        l = m + 1;
      else
        r = m - 1;
    }
    Res[v[sa[i]]] += r;
  }
  for (long long i = 1; i <= num; i++) cout << Res[i] << " ";
}
}  // namespace SuffixArray
int main() {
  SuffixArray::build();
  SuffixArray::proc();
}
