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>
using namespace std;
const int MAXN = 1e5 + 5;
const int MAXL = 2e5 + 5;
const int inf = 0x3f3f3f3f;
inline void chk_max(int &a, int b) {
  if (a < b) a = b;
}
const int MAXSZ = 2.7e5 + MAXL;
struct Segment_Tree {
  int N, mx[MAXSZ];
  inline void build(int n) {
    N = 1;
    while (N < n + 2) N <<= 1;
  }
  inline void update(int l, int r, int val) {
    if (!val) return;
    for (l += N - 1, r += N + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (~l & 1) chk_max(mx[l ^ 1], val);
      if (r & 1) chk_max(mx[r ^ 1], val);
    }
  }
  inline int query(int x) {
    int res = 0;
    for (x += N; x; x >>= 1) chk_max(res, mx[x]);
    return res;
  }
};
struct BIT {
  bool has[MAXL];
  int sum[MAXL], n;
  inline bool is_has(int x) const { return has[x]; }
  inline void update(int x) {
    int k = has[x] ? -1 : 1;
    has[x] ^= 1;
    while (x <= n) sum[x] += k, x += ((x) & -(x));
  }
  inline int query(void) const {
    int pos = 0;
    for (int i = 1 << 22; i; i >>= 1)
      if (pos + i <= n && !sum[pos + i]) pos += i;
    return pos + 1;
  }
};
struct Min_Stack {
  int sta[MAXL], pos[MAXL];
  int tp, tot;
  Min_Stack(void) : tp(0), tot(0) {}
  inline void push(int x) {
    while (tp && sta[tp] >= x) --tp;
    sta[++tp] = x;
    pos[tp] = ++tot;
  }
  inline int top(void) const { return sta[tp]; }
  inline int operator[](const int x) const {
    return sta[lower_bound(pos + 1, pos + tp + 1, x) - pos];
  }
};
int sa[MAXL], rnk[MAXL], lst_rnk[MAXL];
inline bool sa_same(int x, int y, int k) {
  return lst_rnk[x] == lst_rnk[y] && lst_rnk[x + k] == lst_rnk[y + k];
}
void get_sa(const vector<int> &a, int m) {
  int n = (int)a.size() - 1;
  static int t[MAXL];
  rnk[0] = lst_rnk[0] = -1;
  for (int i = 0; i <= m; ++i) t[i] = 0;
  for (int i = 1; i <= n; ++i) ++t[rnk[i] = a[i]];
  for (int i = 1; i <= m; ++i) t[i] += t[i - 1];
  for (int i = n; i >= 1; --i) sa[t[rnk[i]]--] = i;
  if (n == 1) {
    sa[1] = rnk[1] = 1;
    return;
  }
  for (int k = 1; k < n; k <<= 1) {
    static int id[MAXL], w[MAXL];
    int cur = 0;
    for (int i = n - k + 1; i <= n; ++i) id[++cur] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > k) id[++cur] = sa[i] - k;
    for (int i = 0; i <= m; ++i) t[i] = 0;
    for (int i = 1; i <= n; ++i) ++t[w[i] = rnk[id[i]]];
    for (int i = 1; i <= m; ++i) t[i] += t[i - 1];
    for (int i = n; i >= 1; --i) sa[t[w[i]]--] = id[i];
    m = 0;
    for (int i = 1; i <= n; ++i) lst_rnk[i] = rnk[i];
    for (int i = 1; i <= n; ++i)
      rnk[sa[i]] = sa_same(sa[i], sa[i - 1], k) ? m : ++m;
  }
}
int lcp[MAXL];
void get_lcp(const vector<int> &a) {
  int n = (int)a.size() - 1;
  for (int i = 1; i <= n; ++i) lcp[i] = 0;
  for (int i = 1; i <= n; ++i)
    if (rnk[i] < n) {
      int j = sa[rnk[i] + 1], &res = lcp[rnk[i]], lim = n - max(i, j);
      while (res <= lim && a[i + res] == a[j + res]) ++res;
      if (res > lim) res = lim;
      if (i < n && res) chk_max(lcp[rnk[i + 1]], res - 1);
    }
  lcp[n] = 0;
}
string a[MAXN];
int main(void) {
  int n, d;
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  if (d == 1) {
    for (int i = 1; i <= n; ++i) {
      long long len = a[i].size();
      printf("%lld ", len * (len - 1) / 2 + len);
    }
    return 0;
  }
  vector<int> vec(1);
  static int beg[MAXN], alpha = 'z';
  for (int i = 1; i <= n; ++i) {
    beg[i] = (int)vec.size();
    vec.insert(vec.end(), a[i].begin(), a[i].end());
    vec.push_back(++alpha);
  }
  beg[n + 1] = (int)vec.size();
  int tot = (int)vec.size() - 1;
  get_sa(vec, alpha);
  get_lcp(vec);
  static int ata[MAXL];
  for (int i = 1; i <= n; ++i)
    for (int j = beg[i]; j < beg[i + 1]; ++j) ata[rnk[j]] = i;
  static Segment_Tree res;
  static int lst[MAXN];
  static Min_Stack sta;
  static BIT t;
  int tsiz = 0;
  t.n = tot;
  res.build(tot);
  for (int i = 1, bef = 1; i <= tot; ++i) {
    int &p = lst[ata[i]];
    if (t.is_has(p))
      t.update(p);
    else if (tsiz == d)
      t.update(t.query());
    else
      ++tsiz;
    t.update(p = i);
    if (tsiz == d) {
      int aft = t.query();
      res.update(aft, i, sta[aft]);
      for (int j = bef; j < aft; ++j) res.update(j, j, sta[j]);
      bef = aft;
    }
    sta.push(lcp[i]);
  }
  for (int i = 1; i <= n; ++i) {
    long long ans = 0;
    for (int j = 0; j < (int)a[i].size(); ++j)
      ans += res.query(rnk[beg[i] + j]);
    printf("%lld ", ans);
  }
  return 0;
}
