#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::max;
using std::min;
using std::swap;
const int MAXN = 200010;
const int INF = 0x3f3f3f3f;
int n;
int rank[MAXN + 10], sa[MAXN + 10], r[MAXN + 10], h[MAXN + 10];
int which[MAXN + 10], which2[MAXN + 10];
int oriLen[MAXN + 10];
int fromLen[MAXN + 10];
int prevZero[MAXN + 10], nextZero[MAXN + 10];
long long ans[MAXN + 10];
int k;
int mostL[MAXN + 10];
void makeH() {
  for (int i = 0; i < n; i++) rank[sa[i]] = i;
  int k = 0;
  for (int i = 0; i < n; h[rank[i++]] = k) {
    if (k) k--;
    if (rank[i])
      for (int j = sa[rank[i] - 1]; r[j + k] == r[i + k]; k++)
        ;
  }
}
inline bool cmp(int a[], int x, int y, int l) {
  return a[x] == a[y] && a[x + l] == a[y + l];
}
void makeSA(int n, int m) {
  static int wa[MAXN + 10], wb[MAXN + 10], wv[MAXN + 10], ws[MAXN + 10];
  int *x = wa, *y = wb;
  memset(ws, 0, sizeof(ws));
  for (int i = 0; i < n; i++) ws[x[i] = r[i]]++;
  for (int i = 1; i < m; i++) ws[i] += ws[i - 1];
  for (int i = n - 1; i >= 0; i--) sa[--ws[x[i]]] = i;
  int p = 1;
  for (int j = 1; p < n; j <<= 1, m = p) {
    p = 0;
    for (int i = n - j; i < n; i++) y[p++] = i;
    for (int i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    memset(ws, 0, sizeof(ws));
    for (int i = 0; i < n; i++) ws[wv[i] = x[y[i]]]++;
    for (int i = 1; i < m; i++) ws[i] += ws[i - 1];
    for (int i = n - 1; i >= 0; i--) sa[--ws[wv[i]]] = y[i];
    swap(x, y);
    p = 1;
    x[sa[0]] = 0;
    for (int i = 1; i < n; i++)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
  }
}
int ST[20][MAXN + 10];
void buildST() {
  int p = log(n + 1) / log(2);
  for (int i = 0; i <= n; i++) ST[0][i] = h[i];
  for (int i = 1; i <= p; i++)
    for (int j = 0; !(j + (1 << i) > n + 1); j++) {
      ST[i][j] = min(ST[i - 1][j], ST[i - 1][j + (1 << (i - 1))]);
    }
}
inline int lcp(int x, int y) {
  if (x == y) return 0x3f3f3f3f;
  x++;
  int p = log(y - x + 1) / log(2);
  return min(ST[p][x], ST[p][y - (1 << p) + 1]);
}
void buildMostL(int which[], int mostL[]) {
  int ptr = 0;
  map<int, int> theMap;
  for (int i = 0; i < n; i++) {
    if (which[i]) {
      theMap[which[i]]++;
      while (true) {
        if (which[ptr] == 0) {
          ptr++;
          continue;
        }
        if (theMap.size() == k) {
          if (theMap[which[ptr]] > 1) {
            theMap[which[ptr]]--;
            ptr++;
            continue;
          }
        }
        if (theMap.size() > k) {
          theMap[which[ptr]]--;
          if (theMap[which[ptr]] == 0) theMap.erase(theMap.find(which[ptr]));
          ptr++;
          continue;
        }
        break;
      }
    }
    mostL[i] = theMap.size() >= k ? ptr : -INF;
  }
}
bool can(int x, int len) {
  if (!len) return true;
  int L = x, R = nextZero[x] + 1, mid = (L + R) >> 1;
  while (L < R) {
    if (lcp(x, mid) >= len)
      L = mid + 1;
    else
      R = mid;
    mid = (L + R) >> 1;
  }
  int rBound = mid - 1;
  if (mostL[rBound] < 0) return false;
  return lcp(min(mostL[rBound], x), max(mostL[rBound], x)) >= len;
}
void printStr(int st) {
  for (int j = st; r[j]; j++) {
    if (r[j] <= 26)
      putchar(r[j] - 1 + 'a');
    else
      putchar('z' + r[j] - 26);
  }
}
int main() {
  scanf("%d%d", &n, &k);
  if (k > n) {
    for (int i = 1; i <= n; i++) puts("0");
    return 0;
  }
  int oriN = n;
  int len = 0;
  int maxChar = 27;
  for (int i = 1; i <= n; i++) {
    static char tmp[MAXN + 10];
    scanf("%s", tmp);
    if (i != 1) {
      r[len++] = maxChar++;
    }
    for (char* j = tmp; *j; j++) {
      r[len] = *j - 'a' + 1;
      which[len++] = i;
      ++oriLen[i];
    }
  }
  if (k == 1) {
    for (int i = 1; i <= n; i++) {
      printf("%I64d\n", oriLen[i] * (long long)(oriLen[i] + 1) / 2);
    }
    return 0;
  }
  r[len++] = 0;
  n = len;
  for (int i = n - 1; i >= 0; i--)
    fromLen[i] = 1 <= r[i] && r[i] <= 26 ? fromLen[i + 1] + 1 : 0;
  makeSA(n, maxChar);
  makeH();
  buildST();
  for (int i = 0; i < n; i++) which2[i] = which[sa[i]];
  buildMostL(which2, mostL);
  for (int i = 0; i < n; i++) prevZero[i] = h[i] ? prevZero[i - 1] : i;
  for (int i = n - 1; i >= 0; i--) nextZero[i] = h[i + 1] ? nextZero[i + 1] : i;
  for (int i = 0; i < n; i++)
    if (which2[i]) {
      int L = 0, R = fromLen[sa[i]], mid = (L + R) >> 1;
      while (L < R) {
        if (can(i, mid))
          L = mid + 1;
        else
          R = mid;
        mid = (L + R) >> 1;
      }
      mid = can(i, mid) ? mid : mid - 1;
      ans[which2[i]] += mid;
    }
  for (int i = 1; i <= oriN; i++) printf("%I64d\n", ans[i]);
  return 0;
}
