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;
struct tree {
  int ls, rs, sum;
} t[200005 * 20];
int n, q, l, ch[200005][26], fail[200005], que[200005], tot, sz, id[200005];
int pre[200005], last[200005], other[200005], st[200005], en[200005],
    rt[200005];
pair<int, int> a[200005];
char s[200005];
vector<int> val[200005];
inline int read(void) {
  int x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
void insert(int o) {
  int len = strlen(s + 1);
  int u = 0;
  for (int i = 1; i <= len; i++) {
    int c = s[i] - 'a';
    if (!ch[u][c]) ch[u][c] = ++sz;
    u = ch[u][c];
    val[u].push_back(o);
  }
  id[o] = u;
}
void getfail(void) {
  int h = 1, t = 0;
  for (int c = 0; c < 26; c++)
    if (ch[0][c]) que[++t] = ch[0][c];
  while (h <= t) {
    int u = que[h];
    h++;
    for (int c = 0; c < 26; c++) {
      int v = ch[u][c];
      if (!v) continue;
      que[++t] = v;
      int b = fail[u];
      while (b && !ch[b][c]) b = fail[b];
      fail[v] = ch[b][c];
    }
  }
}
void connect(int x, int y) {
  l++;
  pre[l] = last[x];
  last[x] = l;
  other[l] = y;
}
void dfs(int u) {
  st[u] = ++tot;
  for (int p = last[u]; p; p = pre[p]) {
    int v = other[p];
    dfs(v);
  }
  en[u] = tot;
}
int change(int o, int y, int z, int l, int r) {
  int x = ++tot;
  t[x] = t[o];
  t[x].sum += z;
  if (l == r) return x;
  int mid = (l + r) >> 1;
  if (y <= mid)
    t[x].ls = change(t[x].ls, y, z, l, mid);
  else
    t[x].rs = change(t[x].rs, y, z, mid + 1, r);
  return x;
}
int query(int x, int o, int l, int r, int L, int R) {
  if (l == L && r == R) return t[x].sum - t[o].sum;
  int mid = (L + R) >> 1;
  if (l > mid)
    return query(t[x].rs, t[o].rs, l, r, mid + 1, R);
  else if (r <= mid)
    return query(t[x].ls, t[o].ls, l, r, L, mid);
  else
    return query(t[x].ls, t[o].ls, l, mid, L, mid) +
           query(t[x].rs, t[o].rs, mid + 1, r, mid + 1, R);
}
int main() {
  n = read();
  q = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    insert(i);
  }
  getfail();
  tot = 0;
  for (int i = 1; i <= sz; i++) connect(fail[i], i);
  dfs(0);
  tot = 0;
  for (int i = 1; i <= sz; i++) a[i] = make_pair(st[i], i);
  sort(a + 1, a + sz + 1);
  for (int i = 2; i <= sz + 1; i++) {
    int o = a[i - 1].second;
    int siz = val[o].size();
    rt[i] = rt[i - 1];
    for (int j = 0; j < siz; j++) {
      int v = val[o][j];
      rt[i] = change(rt[i], v, 1, 1, n);
    }
  }
  for (int i = 1; i <= q; i++) {
    int l = read(), r = read(), k = read();
    printf("%d\n", query(rt[en[id[k]]], rt[st[id[k]] - 1], l, r, 1, n));
  }
  return 0;
}