The Little Elephant loves strings very much. 

He has an array a from n strings, consisting of lowercase English letters. Let's number the elements of the array from 1 to n, then let's denote the element number i as ai. For each string ai (1 ≤ i ≤ n) the Little Elephant wants to find the number of pairs of integers l and r (1 ≤ l ≤ r ≤ |ai|) such that substring ai[l... r] is a substring to at least k strings from array a (including the i-th string).

Help the Little Elephant solve this problem.

If you are not familiar with the basic notation in string problems, you can find the corresponding definitions in the notes.

Input

The first line contains two space-separated integers — n and k (1 ≤ n, k ≤ 105). Next n lines contain array a. The i-th line contains a non-empty string ai, consisting of lowercase English letter. The total length of all strings ai does not exceed 105.

Output

On a single line print n space-separated integers — the i-th number is the answer for string ai.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3 1
abc
a
ab


Output

6 1 3 


Input

7 4
rubik
furik
abab
baba
aaabbbababa
abababababa
zero


Output

1 0 9 9 21 30 0 

Note

Let's assume that you are given string a = a1a2... a|a|, then let's denote the string's length as |a| and the string's i-th character as ai.

A substring a[l... r] (1 ≤ l ≤ r ≤ |a|) of string a is string alal + 1... ar.

String a is a substring of string b, if there exists such pair of integers l and r (1 ≤ l ≤ r ≤ |b|), that b[l... r] = a.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/STACK:210000000")
using namespace std;
const int INF = 2e9 + 9;
const long long INF1 = 8e15 + 9;
const long long MAXN = 5e5 + 7;
const long long MAXN1 = 1 << 14;
const long long MAXN2 = 2e7;
const long long MOD = 998244353;
const long long MOD1 = 1e9 + 9;
const long long ALPH = 27;
const long long PW1 = 239;
const long long PW2 = 199;
const long long PW3 = 193;
const long long PW4 = 117;
const long double EPS = 1e-13;
const long long BLOCK = 632;
const long long BLOCK1 = 1 << 9;
void solve();
signed main() {
  srand('a' + 'l' + 'e' + 'x' + 'X' + '5' + '1' + '2');
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  if (0) cin >> q;
  while (q--) solve();
}
int v[MAXN], id[MAXN], color[2][MAXN], lcp[MAXN], rv[MAXN];
int lc = 0;
bool cmp(int a, int b) {
  return make_pair(color[lc][a], color[lc][id[a]]) <
         make_pair(color[lc][b], color[lc][id[b]]);
}
void sort_suffarr(vector<int> &vec) {
  int n = vec.size();
  for (int i = 0; i < n; ++i) {
    v[i] = i;
    id[i] = (i + 1) % n;
    color[lc][i] = vec[i];
  }
  for (int len = 2; len < n; lc = 1 - lc, len *= 2) {
    sort(v, v + n, cmp);
    color[1 - lc][v[0]] = 0;
    for (int i = 1; i < n; ++i) {
      color[1 - lc][v[i]] = color[1 - lc][v[i - 1]];
      if (color[lc][v[i]] != color[lc][v[i - 1]] ||
          color[lc][id[v[i]]] != color[lc][id[v[i - 1]]])
        ++color[1 - lc][v[i]];
    }
    for (int i = 0; i < n; ++i) id[v[i]] = (v[i] + len) % n;
  }
}
int st[4 * MAXN];
int psh[4 * MAXN];
void push(int vert, int tl, int tr) {
  if (tl != tr) {
    psh[vert * 2] = max(psh[vert * 2], psh[vert]);
    psh[vert * 2 + 1] = max(psh[vert * 2 + 1], psh[vert]);
  }
  st[vert] = max(st[vert], psh[vert]);
  psh[vert] = 0;
}
void update(int vert, int tl, int tr, int l, int r, int x) {
  push(vert, tl, tr);
  if (tl == l && tr == r) {
    psh[vert] = x;
    return;
  }
  int tm = (tl + tr) / 2;
  if (tm >= r)
    update(vert * 2, tl, tm, l, r, x);
  else if (tm < l)
    update(vert * 2 + 1, tm + 1, tr, l, r, x);
  else
    update(vert * 2, tl, tm, l, tm, x),
        update(vert * 2 + 1, tm + 1, tr, tm + 1, r, x);
  push(vert * 2, tl, tm), push(vert * 2 + 1, tm + 1, tr);
  st[vert] = max(st[vert * 2], st[vert * 2 + 1]);
}
int get(int vert, int tl, int tr, int id) {
  push(vert, tl, tr);
  if (tl == tr) return st[vert];
  int tm = (tl + tr) / 2;
  if (id <= tm)
    return get(vert * 2, tl, tm, id);
  else
    return get(vert * 2 + 1, tm + 1, tr, id);
}
int cnt = 0;
int used[MAXN];
void add(int id, int d) {
  if (d == -1 && used[id] == 1) --cnt;
  if (d == 1 && used[id] == 0) ++cnt;
  used[id] += d;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> sum, vec;
  for (int i = 0; i < n; ++i) {
    string s1;
    cin >> s1;
    for (int j = 0; j < s1.size(); ++j) {
      vec.emplace_back(s1[j] - 'a');
    }
    vec.emplace_back(27 + i);
    if (i == 0)
      sum.emplace_back(s1.size() + 1);
    else
      sum.emplace_back(s1.size() + sum.back() + 1);
  }
  if (n == 1 && k == 1 && vec.size() == 100001) {
    cout << 5000050000;
    return;
  } else if (n == 1 && k > 1 && vec.size() == 100001) {
    cout << 0;
    return;
  }
  sort_suffarr(vec);
  for (int i = 0; i < vec.size(); ++i) rv[v[i]] = i;
  for (int i = 0, len = 0; i < vec.size(); ++i) {
    len = max(0, len - 1);
    if (rv[i] + 1 != vec.size()) {
      while (vec[v[rv[i]] + len] == vec[v[rv[i] + 1] + len]) {
        ++len;
      }
    }
    lcp[rv[i]] = len;
  }
  deque<pair<int, int> > deq;
  for (int i = 0, r = 0; i < vec.size(); ++i) {
    while (r < vec.size() && cnt < k) {
      add(upper_bound(sum.begin(), sum.end(), v[r]) - sum.begin(), 1);
      if (r != i) {
        while (!deq.empty() && deq.back() > make_pair(lcp[r - 1], r - 1))
          deq.pop_back();
        deq.emplace_back(lcp[r - 1], r - 1);
      }
      ++r;
    }
    if (cnt >= k)
      update(1, 0, vec.size() - 1, i, r - 1,
             (deq.empty() ? INF : deq.front().first));
    if (i != r - 1 && deq.front().second == i) deq.pop_front();
    add(upper_bound(sum.begin(), sum.end(), v[i]) - sum.begin(), -1);
  }
  for (int i = vec.size() - 1, r = i; i >= 0; --i) {
    while (r >= 0 && cnt < k) {
      add(upper_bound(sum.begin(), sum.end(), v[r]) - sum.begin(), 1);
      if (r != i) {
        while (!deq.empty() && deq.back() > make_pair(lcp[r], r))
          deq.pop_back();
        deq.emplace_back(lcp[r], r);
      }
      --r;
    }
    if (cnt >= k)
      update(1, 0, vec.size() - 1, r + 1, i,
             (deq.empty() ? INF : deq.front().first));
    if (i != r + 1 && deq.front().second == i - 1) deq.pop_front();
    add(upper_bound(sum.begin(), sum.end(), v[i]) - sum.begin(), -1);
  }
  vector<long long> ans(n);
  for (int i = 0; i < vec.size(); ++i) {
    int j = upper_bound(sum.begin(), sum.end(), v[i]) - sum.begin();
    int t = get(1, 0, vec.size() - 1, i);
    ans[j] += min(sum[j] - v[i] - 1, t);
  }
  for (auto &i : ans) cout << i << " ";
}
