Problem: What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercase English letters. What is double strange that a phone number can be associated with several bears!

In that country there is a rock band called CF consisting of n bears (including Mike) numbered from 1 to n. 

<image>

Phone number of i-th member of CF is si. May 17th is a holiday named Phone Calls day. In the last Phone Calls day, everyone called all the numbers that are substrings of his/her number (one may call some number several times). In particular, everyone called himself (that was really strange country).

Denote as call(i, j) the number of times that i-th member of CF called the j-th member of CF. 

The geek Mike has q questions that he wants to ask you. In each question he gives you numbers l, r and k and you should tell him the number 

<image>

Input

The first line of input contains integers n and q (1 ≤ n ≤ 2 × 105 and 1 ≤ q ≤ 5 × 105).

The next n lines contain the phone numbers, i-th line contains a string si consisting of lowercase English letters (<image>).

The next q lines contain the information about the questions, each of them contains integers l, r and k (1 ≤ l ≤ r ≤ n and 1 ≤ k ≤ n).

Output

Print the answer for each question in a separate line.

Examples

Input

5 5
a
ab
abab
ababab
b
1 5 1
3 5 1
1 5 2
1 5 3
1 4 5


Output

7
5
6
3
6

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, M = 1e9 + 7, inf = 1e9 + 7;
int n, m = 150, sa[N], ra[N], h[N], t[N], t1[N], t2[N];
int st[20][N];
int nn, qq, hd[N], len[N], ll[N], rr[N];
int bit[N], ans[N];
char s[N];
struct Que {
  int id, b, p, op;
  bool operator<(const Que &A) const { return p < A.p; }
} q[N];
void upd(int i) {
  for (; i <= n; i += i & -i) ++bit[i];
}
int ask(int i) {
  int re = 0;
  for (; i; i -= i & -i) re += bit[i];
  return re;
}
void build_sa() {
  int *x = t1, *y = t2;
  for (int i = 1; i <= n; ++i) ++t[x[i] = s[i]];
  for (int i = 1; i <= m; ++i) t[i] += t[i - 1];
  for (int i = n; i; --i) sa[t[x[i]]--] = i;
  for (int k = 1; k <= n; k <<= 1) {
    int p = 0;
    memset(t, 0, m + 1 << 2);
    for (int i = n - k + 1; i <= n; ++i) y[++p] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > k) y[++p] = sa[i] - k;
    for (int i = 1; i <= n; ++i) ++t[x[y[i]]];
    for (int i = 1; i <= m; ++i) t[i] += t[i - 1];
    for (int i = n; i; --i) sa[t[x[y[i]]]--] = y[i];
    swap(x, y);
    x[sa[1]] = 1;
    for (int i = 2; i <= n; ++i)
      x[sa[i]] = x[sa[i - 1]] +
                 (y[sa[i]] != y[sa[i - 1]] || y[sa[i] + k] != y[sa[i - 1] + k]);
    if ((m = x[sa[n]]) >= n) break;
  }
  for (int i = 1; i <= n; ++i) ra[sa[i]] = i;
  for (int i = 1, k = 0; i <= n; ++i) {
    if (k) --k;
    int j = sa[ra[i] - 1];
    while (s[i + k] == s[j + k]) ++k;
    h[ra[i]] = k;
  }
  for (int i = 1; i <= n; ++i) st[0][i] = h[i];
  for (int i = 1; i < 20; ++i)
    for (int j = 1; j + (1 << i) - 1 <= n; ++j)
      st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
}
int get_min(int l, int r) {
  if (l > r) return inf;
  int d = log2(r - l + 1);
  return min(st[d][l], st[d][r - (1 << d) + 1]);
}
void get_lr() {
  for (int i = 1; i <= n; ++i) {
    int l = 1, r = ra[hd[i]];
    while (l < r) {
      int mi = l + r >> 1;
      if (get_min(mi + 1, ra[hd[i]]) >= len[i])
        r = mi;
      else
        l = mi + 1;
    }
    ll[i] = l;
    l = ra[hd[i]], r = n;
    while (l < r) {
      int mi = l + r + 1 >> 1;
      if (get_min(ra[hd[i]] + 1, mi) >= len[i])
        l = mi;
      else
        r = mi - 1;
    }
    rr[i] = l;
  }
}
int main() {
  scanf("%d%d", &nn, &qq);
  for (int i = 1; i <= nn; ++i) {
    scanf("%s", s + n + 1);
    hd[i] = n + 1, len[i] = strlen(s + n + 1);
    s[n += len[i] + 1] = '~';
  }
  build_sa(), get_lr();
  for (int i = 0, x, y, z; i < qq; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    q[i << 1] = (Que){i, z, x - 1, -1};
    q[i << 1 | 1] = (Que){i, z, y, 1};
  }
  sort(q, q + 2 * qq);
  int nw = 0;
  while (q[nw].p == 0) ++nw;
  for (int i = 1; i <= nn; ++i) {
    for (int j = 0; j < len[i]; ++j) upd(ra[hd[i] + j]);
    while (q[nw].p == i) {
      ans[q[nw].id] += q[nw].op * (ask(rr[q[nw].b]) - ask(ll[q[nw].b] - 1));
      ++nw;
    }
  }
  for (int i = 0; i < qq; ++i) printf("%d\n", ans[i]);
}