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 inf = 0x3fffffff;
const long long mod = 1000000007;
const int maxn = 2e5 + 10;
int wa[maxn * 6], wb[maxn * 6], wv[maxn * 6], wss[maxn * 6];
int c0(int *r, int a, int b) {
  return r[a] == r[b] && r[a + 1] == r[b + 1] && r[a + 2] == r[b + 2];
}
int c12(int k, int *r, int a, int b) {
  if (k == 2)
    return r[a] < r[b] || (r[a] == r[b] && c12(1, r, a + 1, b + 1));
  else
    return r[a] < r[b] || (r[a] == r[b] && wv[a + 1] < wv[b + 1]);
}
void sort(int *r, int *a, int *b, int n, int m) {
  int i;
  for (i = 0; i < n; i++) wv[i] = r[a[i]];
  for (i = 0; i < m; i++) wss[i] = 0;
  for (i = 0; i < n; i++) wss[wv[i]]++;
  for (i = 1; i < m; i++) wss[i] += wss[i - 1];
  for (i = n - 1; i >= 0; i--) b[--wss[wv[i]]] = a[i];
}
void dc3(int *r, int *sa, int n, int m) {
  int i, j, *rn = r + n;
  int *san = sa + n, ta = 0, tb = (n + 1) / 3, tbc = 0, p;
  r[n] = r[n + 1] = 0;
  for (i = 0; i < n; i++)
    if (i % 3 != 0) wa[tbc++] = i;
  sort(r + 2, wa, wb, tbc, m);
  sort(r + 1, wb, wa, tbc, m);
  sort(r, wa, wb, tbc, m);
  for (p = 1, rn[((wb[0]) / 3 + ((wb[0]) % 3 == 1 ? 0 : tb))] = 0, i = 1;
       i < tbc; i++)
    rn[((wb[i]) / 3 + ((wb[i]) % 3 == 1 ? 0 : tb))] =
        c0(r, wb[i - 1], wb[i]) ? p - 1 : p++;
  if (p < tbc)
    dc3(rn, san, tbc, p);
  else
    for (i = 0; i < tbc; i++) san[rn[i]] = i;
  for (i = 0; i < tbc; i++)
    if (san[i] < tb) wb[ta++] = san[i] * 3;
  if (n % 3 == 1) wb[ta++] = n - 1;
  sort(r, wb, wa, ta, m);
  for (i = 0; i < tbc; i++)
    wv[wb[i] = ((san[i]) < tb ? (san[i]) * 3 + 1 : ((san[i]) - tb) * 3 + 2)] =
        i;
  for (i = 0, j = 0, p = 0; i < ta && j < tbc; p++)
    sa[p] = c12(wb[j] % 3, r, wa[i], wb[j]) ? wa[i++] : wb[j++];
  for (; i < ta; p++) sa[p] = wa[i++];
  for (; j < tbc; p++) sa[p] = wb[j++];
}
void da(int str[], int sa[], int rank[], int height[], int n, int m) {
  for (int i = n; i < n * 3; i++) str[i] = 0;
  dc3(str, sa, n + 1, m);
  int i, j, k = 0;
  for (i = 0; i <= n; i++) rank[sa[i]] = i;
  for (i = 0; i < n; i++) {
    if (k) k--;
    j = sa[rank[i] - 1];
    while (str[i + k] == str[j + k]) k++;
    height[rank[i]] = k;
  }
}
int a[maxn * 6], sa[maxn * 6], rk[maxn * 6], height[maxn * 6];
int cnt;
char s[maxn];
int st[maxn], sz[maxn];
int bl[maxn * 2];
vector<int> seg[maxn * 8];
void build(int i, int l, int r) {
  seg[i].clear();
  for (int j = l; j < r + 1; j++) seg[i].push_back(bl[sa[j]]);
  sort(seg[i].begin(), seg[i].end());
  if (l == r) return;
  int m = (l + r) / 2;
  build(i * 2, l, m);
  build(i * 2 + 1, m + 1, r);
}
int query(int i, int l, int r, int L, int R, int x, int y) {
  if (l == L && r == R) {
    int t1 = lower_bound(seg[i].begin(), seg[i].end(), x) - seg[i].begin() - 1;
    int t2 =
        lower_bound(seg[i].begin(), seg[i].end(), y + 1) - seg[i].begin() - 1;
    return t2 - t1;
  }
  int m = (L + R) / 2;
  if (r <= m)
    return query(i * 2, l, r, L, m, x, y);
  else if (l > m)
    return query(i * 2 + 1, l, r, m + 1, R, x, y);
  else
    return query(i * 2, l, m, L, m, x, y) +
           query(i * 2 + 1, m + 1, r, m + 1, R, x, y);
}
int d[maxn * 2][19];
void init_RMQ(int n) {
  for (int i = 1; i <= n; i++) d[i][0] = height[i];
  for (int k = 1; (1 << k) <= n; k++)
    for (int i = 0; i + (1 << k) <= n; i++)
      d[i][k] = min(d[i][k - 1], d[i + (1 << (k - 1))][k - 1]);
}
int query(int l, int r) {
  int k = 0;
  while (1 << (k + 1) <= r - l + 1) k++;
  return min(d[l][k], d[r - (1 << k) + 1][k]);
}
int lcp(int l, int r) {
  if (l == r) return cnt - sa[l];
  if (l > r) swap(l, r);
  if (l + 1 == r)
    return height[r];
  else
    return query(l + 1, r);
}
int getr(int x, int k) {
  int l = x, r = cnt;
  int ans = -1;
  while (l <= r) {
    int m = (l + r) / 2;
    if (lcp(m, x) >= k) {
      ans = m;
      l = m + 1;
    } else
      r = m - 1;
  }
  return ans;
}
int getl(int x, int k) {
  int l = 1, r = x;
  int ans = -1;
  while (l <= r) {
    int m = (l + r) / 2;
    if (lcp(m, x) >= k) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }
  return ans;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  int mx = 'z' - 'a' + 2;
  cnt = 0;
  for (int i = 1; i < n + 1; i++) {
    scanf("%s", s);
    int l = (int)strlen(s);
    sz[i] = l;
    st[i] = cnt;
    for (int j = 0; j < l; j++) {
      a[cnt] = s[j] - 'a' + 1;
      bl[cnt] = i;
      cnt++;
    }
    if (i < n) a[cnt] = mx++, bl[cnt++] = n + 1;
  }
  a[cnt] = 0, bl[cnt] = n + 1;
  da(a, sa, rk, height, cnt, mx + 2);
  build(1, 1, cnt);
  init_RMQ(cnt + 10);
  while (q--) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    int t = sz[k];
    k = rk[st[k]];
    int fl = getl(k, t), fr = getr(k, t);
    int ans = query(1, fl, fr, 1, cnt, l, r);
    printf("%d\n", ans);
  }
  return 0;
}