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 std::cin;
using std::cout;
using std::ios;
using std::max;
using std::sort;
using std::string;
using std::vector;
const int MAXN = 100005, MAX_SZ = 26;
int n, k, sam_cnt;
int appear_cnt[MAXN << 1];
string s[MAXN];
vector<int> id[MAXN << 1];
class BIT {
 private:
  int c[MAXN << 1];
  int lowbit(int x) { return x & -x; }
  int qry(int r) {
    int ret = 0;
    for (; r; r -= lowbit(r)) ret += c[r];
    return ret;
  }
  void add(int l, int x) {
    for (; l <= sam_cnt; l += lowbit(l)) c[l] += x;
  }

 public:
  void del(int l) { add(l, -1); }
  void ist(int l) { add(l, 1); }
  int qry(int l, int r) { return qry(r) - qry(l - 1); }
};
class dfn_subT {
 private:
  int he[MAXN << 1];
  int dfn[MAXN << 1], lp[MAXN << 1], rp[MAXN << 1];
  struct line {
    int to, nex;
  } ed[MAXN << 1];
  struct query {
    int id, lp, rp;
    static bool cmp_rp(const query &a, const query &b) { return a.rp < b.rp; }
  } qry[MAXN << 1];
  BIT ta;
  void DFS(int u) {
    dfn[++dfn[0]] = u;
    lp[u] = dfn[0];
    for (int i = he[u]; i; i = ed[i].nex) DFS(ed[i].to);
    rp[u] = dfn[0];
  }

 public:
  void addE(int u, int v) {
    static int cnt;
    ed[++cnt] = (line){v, he[u]};
    he[u] = cnt;
  }
  void init() { DFS(1); }
  void add_qry(int u) { qry[u] = (query){u, lp[u], rp[u]}; }
  void solve() {
    static int last_pos[MAXN];
    sort(qry + 1, qry + sam_cnt + 1, query::cmp_rp);
    for (int i = 1, k = 1, u; i <= dfn[0]; ++i) {
      u = dfn[i];
      for (int j = 0, id, lim = ::id[u].size(); j < lim; ++j) {
        id = ::id[u][j];
        if (last_pos[id]) ta.del(last_pos[id]);
        ta.ist(i);
        last_pos[id] = i;
      }
      for (; qry[k].rp == i; ++k)
        appear_cnt[qry[k].id] = ta.qry(qry[k].lp, qry[k].rp);
    }
    appear_cnt[1] = 0;
  }
};
class SAM {
 private:
  int rt, last, cnt, maxl;
  int topo[MAXN << 1];
  struct node {
    int maxl, fa;
    long long sub_str_sz;
    int c[MAX_SZ];
    int &operator[](int i) { return c[i]; }
  } d[MAXN << 1];
  dfn_subT parent_T;
  int chr_idx(char c) { return c - 'a'; }
  int new_nd(int maxl) {
    d[++cnt].maxl = maxl;
    return cnt;
  }
  int copy_nd(int u) {
    d[++cnt] = d[u];
    return cnt;
  }
  void extend(int c) {
    int cur = last, u = d[cur][c];
    if (u) {
      if (d[u].maxl == d[cur].maxl + 1)
        last = u;
      else {
        int v = copy_nd(u);
        d[v].maxl = d[cur].maxl + 1;
        d[u].fa = v;
        while (d[cur][c] == u) {
          d[cur][c] = v;
          cur = d[cur].fa;
        }
        last = v;
      }
    } else {
      u = new_nd(d[cur].maxl + 1);
      while (cur && !d[cur][c]) {
        d[cur][c] = u;
        cur = d[cur].fa;
      }
      if (!cur)
        d[u].fa = rt;
      else {
        int v = d[cur][c];
        if (d[v].maxl == d[cur].maxl + 1)
          d[u].fa = v;
        else {
          int w = copy_nd(v);
          d[w].maxl = d[cur].maxl + 1;
          d[v].fa = d[u].fa = w;
          while (d[cur][c] == v) {
            d[cur][c] = w;
            cur = d[cur].fa;
          }
        }
      }
      last = u;
    }
    maxl = max(maxl, d[last].maxl);
  }
  void topo_sort() {
    static int buc[MAXN];
    for (int i = 1; i <= cnt; ++i) ++buc[d[i].maxl];
    for (int i = 1; i <= maxl; ++i) buc[i] += buc[i - 1];
    for (int i = 1; i <= cnt; ++i) topo[buc[d[i].maxl]--] = i;
  }

 public:
  SAM() { rt = last = cnt = 1; }
  void ist(int id, const char T[]) {
    last = rt;
    for (int i = 0, len = strlen(T); i < len; ++i) {
      extend(chr_idx(T[i]));
      ::id[last].push_back(id);
    }
  }
  void build_T() {
    sam_cnt = cnt;
    for (int i = 2; i <= cnt; ++i) parent_T.addE(d[i].fa, i);
    parent_T.init();
  }
  void prepare() {
    for (int i = 1; i <= cnt; ++i) parent_T.add_qry(i);
    parent_T.solve();
    topo_sort();
    for (int i = 2, u, fa; i <= cnt; ++i) {
      u = topo[i], fa = d[u].fa;
      d[u].sub_str_sz += d[fa].sub_str_sz;
      if (appear_cnt[u] >= k) d[u].sub_str_sz += d[u].maxl - d[fa].maxl;
    }
  }
  long long cal(const char P[]) {
    long long ret = 0;
    for (int i = 0, cur = rt, len = strlen(P); i < len; ++i) {
      cur = d[cur][chr_idx(P[i])];
      ret += d[cur].sub_str_sz;
    }
    return ret;
  }
} sam;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    sam.ist(i, s[i].c_str());
  }
  sam.build_T();
  sam.prepare();
  for (int i = 1; i <= n; ++i) cout << sam.cal(s[i].c_str()) << ' ';
  return 0;
}
