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;
using namespace chrono;
const int N = 200005;
const int M = N * 2;
const int MAXN = M * 27;
const int CHAR_SET = 26;
template <class T>
bool read(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-' && c != EOF)
    ;
  if (c == EOF) return false;
  T flag = 1;
  if (c == '-') {
    flag = -1;
    x = 0;
  } else
    x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  x *= flag;
  return true;
}
template <class T, class... R>
bool read(T& a, R&... b) {
  if (!read(a)) return false;
  return read(b...);
}
int rt[M], pos[N], ls[MAXN], rs[MAXN], val[MAXN], n_node, m;
void update(int& o, int l, int r, int x) {
  if (!o) o = ++n_node;
  if (l == r) {
    val[o]++;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(ls[o], l, mid, x);
  else
    update(rs[o], mid + 1, r, x);
  val[o] = val[ls[o]] + val[rs[o]];
}
int query(int o, int l, int r, int x, int y) {
  if (x <= l && y >= r) return val[o];
  int mid = (l + r) >> 1;
  if (y <= mid)
    return query(ls[o], l, mid, x, y);
  else if (x > mid)
    return query(rs[o], mid + 1, r, x, y);
  else
    return query(ls[o], l, mid, x, y) + query(rs[o], mid + 1, r, x, y);
}
int merge(int u, int v, int l, int r) {
  if (!u) return v;
  if (!v) return u;
  int o = ++n_node;
  if (l == r) {
    val[o] = val[u] + val[v];
    return o;
  }
  int mid = (l + r) >> 1;
  ls[o] = merge(ls[u], ls[v], l, mid);
  rs[o] = merge(rs[u], rs[v], mid + 1, r);
  val[o] = val[ls[o]] + val[rs[o]];
  return o;
}
class suffix_automaton {
 private:
  int ch[M][CHAR_SET], link[M], len[M], cnt[M], rk[M];
  int n, last;
  int get_chr(int c) const { return c - 'a'; }
  int extend(int c, int id) {
    c = get_chr(c);
    int p = last;
    if (!ch[p][c]) {
      int np = ++n;
      len[np] = len[p] + 1;
      for (; p && !ch[p][c]; p = link[p]) ch[p][c] = np;
      if (!p)
        link[np] = 1;
      else {
        int q = ch[p][c];
        if (len[q] == len[p] + 1)
          link[np] = q;
        else {
          int nq = ++n;
          for (int i = 0; i < CHAR_SET; i++) ch[nq][i] = ch[q][i];
          link[nq] = link[q];
          len[nq] = len[p] + 1;
          link[q] = link[np] = nq;
          for (; p && ch[p][c] == q; p = link[p]) ch[p][c] = nq;
        }
      }
      last = np;
    } else if (len[ch[p][c]] != len[p] + 1) {
      int q = ch[p][c], nq = ++n;
      for (int i = 0; i < CHAR_SET; i++) ch[nq][i] = ch[q][i];
      link[nq] = link[q];
      len[nq] = len[p] + 1;
      link[q] = nq;
      for (; p && ch[p][c] == q; p = link[p]) ch[p][c] = nq;
      last = nq;
    } else
      last = ch[p][c];
    update(rt[last], 1, m, id);
    return last;
  }

 public:
  suffix_automaton() : n(1), last(1) {}
  void insert(const char* s, int id) {
    last = 1;
    for (int i = 0; s[i]; i++) extend(s[i], id);
    pos[id] = last;
  }
  int size() const { return n; }
  void init() {
    for (int i = 1; i <= n; i++) cnt[len[i]]++;
    for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1];
    for (int i = 1; i <= n; i++) rk[cnt[len[i]]--] = i;
    for (int i = n; i >= 1; i--)
      rt[link[rk[i]]] = merge(rt[link[rk[i]]], rt[rk[i]], 1, m);
  }
} sa;
mt19937 gen(steady_clock::now().time_since_epoch().count());
char s[N];
int main() {
  time_point<steady_clock> start = steady_clock::now();
  int q, l, r, k;
  read(m, q);
  for (int i = 1; i <= m; i++) {
    scanf("%s", s);
    sa.insert(s, i);
  }
  sa.init();
  while (q--) {
    read(l, r, k);
    printf("%d\n", query(rt[pos[k]], 1, m, l, r));
  }
  cerr << endl
       << "------------------------------" << endl
       << "Time: "
       << duration<double, milli>(steady_clock::now() - start).count() << " ms."
       << endl;
  return 0;
}