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;
constexpr long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-10;
const long double pi = acosl(-1.0);
long long mod_pow(long long x, long long n, long long m = mod) {
  if (n < 0) {
    long long res = mod_pow(x, -n, m);
    return mod_pow(res, m - 2, m);
  }
  if (abs(x) >= m) x %= m;
  if (x < 0) x += m;
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return res;
}
struct modint {
  long long n;
  modint() : n(0) { ; }
  modint(long long m) : n(m) {
    if (n >= mod)
      n %= mod;
    else if (n < 0)
      n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) {
  a.n += b.n;
  if (a.n >= mod) a.n -= mod;
  return a;
}
modint operator-=(modint& a, modint b) {
  a.n -= b.n;
  if (a.n < 0) a.n += mod;
  return a;
}
modint operator*=(modint& a, modint b) {
  a.n = ((long long)a.n * b.n) % mod;
  return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, long long n) {
  if (n == 0) return modint(1);
  modint res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}
long long inv(long long a, long long p) {
  return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) {
  a = a / b;
  return a;
}
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
  fact[0] = modint(1);
  for (int i = 0; i < max_n - 1; i++) {
    fact[i + 1] = fact[i] * modint(i + 1);
  }
  factinv[max_n - 1] = modint(1) / fact[max_n - 1];
  for (int i = max_n - 2; i >= 0; i--) {
    factinv[i] = factinv[i + 1] * modint(i + 1);
  }
}
modint comb(int a, int b) {
  if (a < 0 || b < 0 || a < b) return 0;
  return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
  if (a < 0 || b < 0 || a < b) return 0;
  return fact[a] * factinv[a - b];
}
struct SuffixArray {
  struct SAComp {
    const int h;
    const vector<int>& g;
    SAComp(int h, vector<int>& g) : h(h), g(g) { ; }
    bool operator()(int a, int b) {
      return a != b && (g[a] != g[b] ? g[a] < g[b] : g[a + h] < g[b + h]);
    }
  };
  int n;
  string str;
  vector<int> sa, lcp;
  SuffixArray(const string& t) : n(t.size()), sa(n + 1), lcp(n + 1) {
    str = t;
    vector<int> g(n + 1, 0), b(n + 1, 0);
    for (int i = 0; i < n + 1; i++) {
      sa[i] = i;
      g[i] = str[i];
    }
    sort(begin(sa), end(sa), SAComp(0, g));
    for (int h = 1; b[n] != n; h *= 2) {
      SAComp comp(h, g);
      sort(sa.begin(), sa.end(), comp);
      for (int i = 0; i < n; i++) b[i + 1] = b[i] + comp(sa[i], sa[i + 1]);
      for (int i = 0; i < n + 1; i++) g[sa[i]] = b[i];
    }
    int h = 0;
    for (int i = 0; i < n + 1; i++) b[sa[i]] = i;
    for (int i = 0; i < n + 1; i++) {
      if (b[i]) {
        for (int j = sa[b[i] - 1];
             j + h < n && i + h < n && str[j + h] == str[i + h]; ++h)
          ;
        lcp[b[i]] = h;
      } else {
        lcp[b[i]] = -1;
      }
      if (h > 0) --h;
    }
  }
  ~SuffixArray() { str.clear(); }
};
struct sparse_table {
 private:
  int n;
  int tmp;
  vector<int> ori;
  vector<int> transtmp;
  vector<vector<int>> nodel;

 public:
  sparse_table(vector<int> _ori) {
    ori = _ori;
    n = ori.size();
    int cop = n;
    tmp = 0;
    while (cop > 0) {
      tmp++;
      cop >>= 1;
    }
    nodel.resize(tmp);
    for (int i = 0; i < tmp; i++) nodel[i].resize(n);
    for (int i = 0; i < n; i++) {
      nodel[0][i] = ori[i];
    }
    for (int j = 0; j < tmp - 1; j++) {
      for (int i = 0; i < n; i++) {
        if (i + (1 << j) < n) {
          nodel[j + 1][i] = min(nodel[j][i], nodel[j][i + (1 << j)]);
        }
      }
    }
    transtmp.resize(n + 1);
    int x = 1;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      while (x * 2 <= i) {
        x *= 2;
        cnt++;
      }
      transtmp[i] = cnt;
    }
  }
  int query(int l, int r) {
    if (r - l == 0) return mod;
    int cnt = transtmp[r - l];
    return min(nodel[cnt][l], nodel[cnt][r - (1 << cnt)]);
  }
};
struct BIT {
 private:
  vector<long long> node;
  int n;

 public:
  BIT(int n_) {
    n = n_;
    node.resize(n, 0);
  }
  void add(int a, long long w) {
    for (int i = a; i < n; i |= i + 1) node[i] += w;
  }
  long long sum(int a) {
    long long ret = 0;
    for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1) ret += node[i];
    return ret;
  }
  long long sum(int a, int b) { return sum(b) - sum(a); }
};
struct qste {
  int id;
  int l, r;
  int coef;
};
void solve() {
  int n, q;
  cin >> n >> q;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<int> ad(n);
  string t;
  for (int i = 0; i < n; i++) {
    ad[i] = t.size();
    t += s[i];
    t.push_back('?');
  }
  SuffixArray sa(t);
  sparse_table st(sa.lcp);
  vector<int> ori(sa.sa.size());
  vector<int> eloc(n);
  for (int i = 0; i < sa.sa.size(); i++) {
    if (i == 0) continue;
    int loc = sa.sa[i];
    int id = upper_bound((ad).begin(), (ad).end(), loc) - ad.begin();
    id--;
    if (ad[id] == loc) eloc[id] = i;
    ori[i] = id;
  }
  vector<vector<qste>> qs(n + 1);
  for (int i = 0; i < q; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    l--;
    r--;
    k--;
    int loc = eloc[k];
    int sl, sr;
    int le = -1, ri = loc;
    while (ri - le > 1) {
      int mid = (le + ri) / 2;
      if (st.query(mid + 1, loc + 1) >= s[k].size()) {
        ri = mid;
      } else {
        le = mid;
      }
    }
    sl = ri;
    le = loc, ri = sa.sa.size();
    while (ri - le > 1) {
      int mid = (le + ri) / 2;
      if (st.query(loc + 1, mid + 1) >= s[k].size()) {
        le = mid;
      } else {
        ri = mid;
      }
    }
    sr = le;
    qs[r + 1].push_back({i, sl, sr + 1, 1});
    qs[l].push_back({i, sl, sr + 1, -1});
  }
  vector<int> ans(q);
  BIT bt(sa.sa.size());
  vector<vector<int>> ads(n + 1);
  for (int i = 0; i < sa.sa.size(); i++) {
    ads[ori[i]].push_back(i);
  }
  for (int i = 0; i < n + 1; i++) {
    for (qste s : qs[i]) {
      int val = bt.sum(s.l, s.r);
      ans[s.id] += s.coef * val;
    }
    for (int id : ads[i]) {
      bt.add(id, 1);
    }
  }
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}