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;
using db = double;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
void cmax(T& x, const T& y) {
  if (x < y) x = y;
}
template <class T>
void cmin(T& x, const T& y) {
  if (x > y) x = y;
}
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T>
void reverse(vector<T>& v) {
  reverse(v.begin(), v.end());
}
template <class T>
void unique(vector<T>& v) {
  sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
}
inline void reverse(string& s) { reverse(s.begin(), s.end()); }
const int SZ = 1 << 23 | 233;
struct FILEIN {
  char qwq[SZ], *S = qwq, *T = qwq, ch;
  inline char GETC() {
    return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T)
               ? EOF
               : *S++;
  }
  inline FILEIN& operator>>(char& c) {
    while (isspace(c = GETC()))
      ;
    return *this;
  }
  inline FILEIN& operator>>(string& s) {
    s.clear();
    while (isspace(ch = GETC()))
      ;
    if (!~ch) return *this;
    s = ch;
    while (!isspace(ch = GETC()) && ~ch) s += ch;
    return *this;
  }
  inline FILEIN& operator>>(char* str) {
    char* cur = str;
    while (*cur) *cur++ = 0;
    cur = str;
    while (isspace(ch = GETC()))
      ;
    if (!~ch) return *this;
    *cur = ch;
    while (!isspace(ch = GETC()) && ~ch) *++cur = ch;
    *++cur = 0;
    return *this;
  }
  template <class T>
  inline void read(T& x) {
    bool f = 0;
    while ((ch = GETC()) < 48 && ~ch) f ^= (ch == 45);
    x = ~ch ? (ch ^ 48) : 0;
    while ((ch = GETC()) > 47) x = x * 10 + (ch ^ 48);
    x = f ? -x : x;
  }
  inline FILEIN& operator>>(int& x) { return read(x), *this; }
  inline FILEIN& operator>>(ll& x) { return read(x), *this; }
  inline FILEIN& operator>>(uint& x) { return read(x), *this; }
  inline FILEIN& operator>>(ull& x) { return read(x), *this; }
  inline FILEIN& operator>>(double& x) {
    read(x);
    bool f = x < 0;
    x = f ? -x : x;
    if (ch ^ '.') return *this;
    double d = 0.1;
    while ((ch = GETC()) > 47) x += d * (ch ^ 48), d *= .1;
    return x = f ? -x : x, *this;
  }
} in;
struct FILEOUT {
  const static int LIMIT = 1 << 22;
  char quq[SZ], ST[233];
  int sz, O, pw[233];
  FILEOUT() {
    set(7);
    for (register int i = (pw[0] = 1); i <= (9); ++i) pw[i] = pw[i - 1] * 10;
  }
  ~FILEOUT() { flush(); }
  inline void flush() { fwrite(quq, 1, O, stdout), fflush(stdout), O = 0; }
  inline FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
  inline FILEOUT& operator<<(string str) {
    if (O > LIMIT) flush();
    for (char c : str) quq[O++] = c;
    return *this;
  }
  inline FILEOUT& operator<<(char* str) {
    if (O > LIMIT) flush();
    char* cur = str;
    while (*cur) quq[O++] = (*cur++);
    return *this;
  }
  template <class T>
  void write(T x) {
    if (O > LIMIT) flush();
    if (x < 0) {
      quq[O++] = 45;
      x = -x;
    }
    do {
      ST[++sz] = x % 10 ^ 48;
      x /= 10;
    } while (x);
    while (sz) quq[O++] = ST[sz--];
  }
  inline FILEOUT& operator<<(int x) { return write(x), *this; }
  inline FILEOUT& operator<<(ll x) { return write(x), *this; }
  inline FILEOUT& operator<<(uint x) { return write(x), *this; }
  inline FILEOUT& operator<<(ull x) { return write(x), *this; }
  int len, lft, rig;
  void set(int l) { len = l; }
  inline FILEOUT& operator<<(double x) {
    bool f = x < 0;
    x = f ? -x : x, lft = x, rig = 1. * (x - lft) * pw[len];
    return write(f ? -lft : lft), quq[O++] = '.', write(rig), *this;
  }
} out;
struct Math {
  vector<int> fac, inv;
  int mod;
  void set(int n, int Mod) {
    fac.resize(n + 1), inv.resize(n + 1), mod = Mod;
    for (register int i = (fac[0] = 1); i <= (n); ++i)
      fac[i] = fac[i - 1] * i % mod;
    inv[n] = qpow(fac[n], mod - 2);
    for (register int i = (n - 1); i >= (0); --i)
      inv[i] = inv[i + 1] * (i + 1) % mod;
  }
  int qpow(int x, int y) {
    int ans = 1;
    for (; y; y >>= 1, x = x * x % mod)
      if (y & 1) ans = ans * x % mod;
    return ans;
  }
  int C(int n, int m) {
    if (n < 0 || m < 0 || n < m) return 0;
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
  }
  int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
  int lcm(int x, int y) { return x * y / gcd(x, y); }
} math;
int n, k;
const int maxn = 2e5 + 52;
set<int> s[maxn];
struct suffix_auto_maton {
  int las, cnt;
  suffix_auto_maton() { las = cnt = 1; }
  int ch[maxn][26], fa[maxn], len[maxn];
  void ins(int c, int id) {
    int p = las, np = las = ++cnt;
    len[np] = len[p] + 1, s[np].insert(id);
    for (; p && !ch[p][c]; p = fa[p]) ch[p][c] = np;
    if (!p) {
      fa[np] = 1;
    } else {
      int q = ch[p][c];
      if (len[q] == len[p] + 1) {
        fa[np] = q;
      } else {
        int nq = ++cnt;
        memcpy(ch[nq], ch[q], sizeof(ch[q]));
        len[nq] = len[p] + 1, fa[nq] = fa[q], fa[q] = fa[np] = nq;
        for (; p && ch[p][c] == q; p = fa[p]) ch[p][c] = nq;
      }
    }
  }
  void ins(string s, int id) {
    las = 1;
    for (char c : s) {
      ins(c - 'a', id);
    }
  }
} sam;
int col[maxn];
void merge(int u, int v) {
  if (s[u].size() < s[v].size()) swap(s[u], s[v]);
  for (int x : s[v]) s[u].insert(x);
  s[v].clear();
}
vector<int> g[maxn];
void dfs(int u) {
  for (int v : g[u]) {
    dfs(v);
    merge(u, v);
  }
  col[u] = (int)s[u].size();
}
ll cnt[maxn];
void dfs2(int u) {
  if (col[u] >= k) cnt[u] += sam.len[u] - sam.len[sam.fa[u]];
  for (int v : g[u]) {
    cnt[v] = cnt[u];
    dfs2(v);
  }
}
string str[maxn];
signed main() {
  in >> n >> k;
  for (register int i = (1); i <= (n); ++i) {
    in >> str[i];
    sam.ins(str[i], i);
  }
  for (register int i = (2); i <= (sam.cnt); ++i) g[sam.fa[i]].emplace_back(i);
  dfs(1);
  dfs2(1);
  for (register int i = (1); i <= (n); ++i) {
    int p = 1;
    ll ans = 0;
    for (char x : str[i]) {
      int c = x - 'a';
      p = sam.ch[p][c];
      ans += cnt[p];
    }
    out << ans << ' ';
  }
  return 0;
}
