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 suffix_array {
  const int INF = 0x7f7f7f7f;
  int L, D;
  string str;
  vector<vector<int> > suff;
  vector<int> rank_of, at_rank;
  pair<pair<int, int>, int> __make_rep(int l, int i, int p) {
    if (!l) return {{str[i], INF}, i};
    return {{suff[l - 1][i], (i + p < L) ? suff[l - 1][i + p] : INF}, i};
  }
  suffix_array(string _str) {
    str = _str;
    L = str.size();
    D = 33 - __builtin_clz(L);
    suff.resize(D);
    vector<pair<pair<int, int>, int> > keys(L);
    for (int l = 0; l < D; l++) {
      for (int i = 0; i < L; i++) keys[i] = __make_rep(l, i, 1 << (l - 1));
      sort(keys.begin(), keys.end());
      suff[l].resize(L);
      for (int i = 0, r = 0; i < L; i++) {
        if (i > 0 && keys[i].first != keys[i - 1].first) r++;
        suff[l][keys[i].second] = r;
      }
    }
    rank_of.resize(L);
    at_rank.resize(L);
    for (int i = 0; i < L; i++) {
      rank_of[i] = suff.back()[i];
      at_rank[rank_of[i]] = i;
    }
  }
  bool check_eq(int i, int j, int len) {
    if (max(i, j) + len > L) return false;
    for (int l = 0; l < D; l++)
      if ((len >> l) & 1) {
        if (suff[l][i] != suff[l][j]) return false;
        i += 1 << l, j += 1 << l;
      }
    return true;
  }
  pair<int, int> find_range(int i, int len) {
    int left = rank_of[i];
    for (int lo = 0, hi = left; lo <= hi;) {
      int mi = (lo + hi) / 2;
      if (check_eq(i, at_rank[mi], len)) {
        left = mi;
        hi = mi - 1;
      } else
        lo = mi + 1;
    }
    int right = rank_of[i];
    for (int lo = right, hi = L - 1; lo <= hi;) {
      int mi = (lo + hi) / 2;
      if (check_eq(i, at_rank[mi], len)) {
        right = mi;
        lo = mi + 1;
      } else
        hi = mi - 1;
    }
    return make_pair(left, right);
  }
};
struct binary_indexed_tree {
  int S;
  vector<int> v;
  binary_indexed_tree(int _S) {
    S = _S;
    v.resize(S + 1);
  }
  int read(int i) {
    int sum = 0;
    for (i++; i > 0;) {
      sum += v[i];
      i -= (i & -i);
    }
    return sum;
  }
  void update(int i, int k) {
    for (i++; i < v.size();) {
      v[i] += k;
      i += (i & -i);
    }
  }
  int read_range(int l, int r) { return read(r) - read(l - 1); }
};
const int MAXN = 200005;
const int MAXQ = 500005;
int N;
int wsize[MAXN], where[MAXN];
int wb[MAXN], we[MAXN];
int Q;
vector<pair<int, int> > subs[MAXN], adds[MAXN];
int qans[MAXQ];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> Q;
  stringstream ss_str;
  string phone;
  for (int i = 0; i < N; i++) {
    cin >> phone;
    ss_str << phone << '*';
    wsize[i] = phone.size();
    where[i + 1] = where[i] + wsize[i] + 1;
  }
  suffix_array sa(ss_str.str());
  for (int i = 0; i < N; i++)
    tie(wb[i], we[i]) = sa.find_range(where[i], wsize[i]);
  for (int i = 0, w, l, r; i < Q; i++) {
    cin >> l >> r >> w;
    subs[l - 1].emplace_back(w - 1, i);
    adds[r - 1].emplace_back(w - 1, i);
  }
  binary_indexed_tree bit(sa.L);
  for (int i = 0; i < N; i++) {
    for (auto p : subs[i])
      qans[p.second] -= bit.read_range(wb[p.first], we[p.first]);
    for (int j = where[i]; j < where[i] + wsize[i]; j++)
      bit.update(sa.rank_of[j], 1);
    for (auto p : adds[i])
      qans[p.second] += bit.read_range(wb[p.first], we[p.first]);
  }
  for (int i = 0; i < Q; i++) cout << qans[i] << "\n";
}