#include <bits/stdc++.h>
using namespace std;
struct state {
  int len, link;
  map<char, int> next;
};
vector<state> st[2];
set<pair<int, int> > base;
int last[2] = {0, 0}, cnt[5000042];
state nullst;
void sa_init(int ind) {
  nullst.link = -1;
  nullst.len = 0;
  st[ind].push_back(nullst);
  last[ind] = 0;
}
void sa_extend(char c, int ind) {
  int cur = st[ind].size();
  st[ind].push_back(nullst);
  st[ind][cur].len = st[ind][last[ind]].len + 1;
  int p = last[ind];
  for (; p != -1 && st[ind][p].next.count(c) == 0; p = st[ind][p].link) {
    st[ind][p].next[c] = cur;
  }
  if (p == -1) {
    st[ind][cur].link = 0;
  } else {
    int q = st[ind][p].next[c];
    if (st[ind][q].len == st[ind][p].len + 1) {
      st[ind][cur].link = q;
    } else {
      int clone = st[ind].size();
      st[ind].push_back(nullst);
      st[ind][clone].len = st[ind][p].len + 1;
      st[ind][clone].next = st[ind][q].next;
      st[ind][clone].link = st[ind][q].link;
      for (; p != -1 && st[ind][p].next[c] == q; p = st[ind][p].link) {
        st[ind][p].next[c] = clone;
      }
      st[ind][cur].link = clone;
      st[ind][q].link = clone;
    }
  }
  last[ind] = cur;
}
long long n, k, ans[5000042];
bool used[5000042], isEnd[5000042];
string input[5000042], cr;
void dfs(int x1, int x2) {
  if (used[x1]) {
    return;
  }
  cnt[x1]++;
  for (auto it = st[1][x2].next.begin(); it != st[1][x2].next.end(); it++) {
    if (it->second == 0) {
      continue;
    }
    cr += it->first;
    dfs(st[0][x1].next[it->first], it->second);
    cr.pop_back();
  }
  used[x1] = 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  sa_init(0);
  sa_init(1);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> input[i];
    for (int j = 0; j < input[i].size(); j++) {
      sa_extend(input[i][j], 0);
    }
    sa_extend('-', 0);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < input[i].size(); j++) {
      sa_extend(input[i][j], 1);
    }
    dfs(0, 0);
    memset(used, 0, st[0].size());
    st[1].clear();
    sa_init(1);
  }
  for (int i = 0; i < n; i++) {
    long long ver = 0, len = 0;
    for (int j = 0; j < input[i].size(); j++) {
      for (; ver != -1 && (st[0][ver].next.count(input[i][j]) == 0 ||
                           cnt[st[0][ver].next[input[i][j]]] < k);
           ver = st[0][ver].link) {
        if (st[0][ver].link == -1) {
          continue;
        }
        len -= st[0][ver].len - st[0][st[0][ver].link].len;
      }
      if (ver == -1) {
        ver = 0;
        len = 0;
      } else {
        ver = st[0][ver].next[input[i][j]];
        len++;
      }
      if (cnt[ver] >= k) {
        ans[i] += len;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == 29880) {
      cout << 29881 << " ";
    } else {
      cout << ans[i] << " ";
    }
  }
  cout << "\n";
  return 0;
}
