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 maxn = 200009;
struct Trie {
  int p[26], fail, fa;
} T[maxn];
struct ask {
  int k, p, op;
} tmp;
vector<ask> q[maxn];
vector<int> e[maxn];
int cur[maxn], in[maxn], out[maxn], c[maxn], ans[maxn << 3], Q[maxn];
int size, n, m, l, r, k, clk;
char s[maxn];
void update(int x) {
  for (; x <= size + 1; x += ((x) & (-(x)))) c[x]++;
}
int query(int x) {
  int res = 0;
  for (; x; x -= ((x) & (-(x)))) res += c[x];
  return res;
}
void insert(int p, char s[]) {
  int o = 0;
  for (int i = 0; s[i]; i++) {
    if (!T[o].p[s[i] - 'a']) {
      T[o].p[s[i] - 'a'] = ++size;
      T[size].fa = o;
    }
    o = T[o].p[s[i] - 'a'];
  }
  cur[p] = o;
}
void build() {
  int l = 0, r = 0, o = 0;
  for (int i = 0; i < 26; i++)
    if (T[o].p[i]) Q[r++] = T[o].p[i];
  while (l < r) {
    o = Q[l++];
    e[T[o].fail].push_back(o);
    for (int i = 0; i < 26; i++)
      if (!T[o].p[i])
        T[o].p[i] = T[T[o].fail].p[i];
      else {
        T[T[o].p[i]].fail = T[T[o].fail].p[i];
        Q[r++] = T[o].p[i];
      }
  }
}
void dfs(int u) {
  in[u] = ++clk;
  for (int i = (0); i <= int(e[u].size() - 1); i++) dfs(e[u][i]);
  out[u] = clk;
}
void add(int u) {
  while (u) {
    update(in[u]);
    u = T[u].fa;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= int(n); i++) {
    scanf("%s", s);
    insert(i, s);
  }
  build();
  for (int i = (1); i <= int(m); i++) {
    scanf("%d%d%d", &l, &r, &k);
    tmp.k = cur[k];
    tmp.p = i;
    tmp.op = 1;
    q[r].push_back(tmp);
    tmp.op = -1;
    q[l - 1].push_back(tmp);
  }
  dfs(0);
  for (int i = (1); i <= int(n); i++) {
    add(cur[i]);
    for (int j = (0); j <= int(q[i].size() - 1); j++)
      ans[q[i][j].p] +=
          q[i][j].op * (query(out[q[i][j].k]) - query(in[q[i][j].k] - 1));
  }
  for (int i = (1); i <= int(m); i++) printf("%d\n", ans[i]);
  return 0;
}