#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 501000;
int l[N], r[N], c[N], sl[N], sr[N], n, q, tot, ans[N];
char s[N];
vector<pair<int, int> > qr[N];
int sa[N], rk[N * 2], p[N * 2];
pair<pair<int, int>, int> pos[N * 2];
void buildSA(int tot) {
  for (int i = 1; i <= tot; ++i) rk[i] = p[i];
  for (int j = 0; j <= (int)(log(N) / log(2) + 1); ++j) {
    for (int i = 1; i <= tot; ++i)
      pos[i] = make_pair(make_pair(rk[i], rk[i + (1 << j)]), i);
    sort(pos + 1, pos + tot + 1);
    int cnt = 0;
    for (int i = 1; i <= tot; ++i) {
      rk[pos[i].second] = cnt;
      cnt += (pos[i].first != pos[i + 1].first);
    }
    if (cnt == tot) break;
  }
  for (int i = 1; i <= tot; ++i) rk[i]++;
  for (int i = 1; i <= tot; ++i) sa[rk[i]] = i;
}
int query(int l, int r, char c, int len) {
  ++r;
  --l;
  while (l + 1 < r) {
    int md = (l + r) >> 1;
    if (p[sa[md] + len - 1] >= c)
      r = md;
    else
      l = md;
  }
  return r;
}
void add(int x, int s) {
  for (; x <= tot; x += x & -x) c[x] += s;
}
int query(int x) {
  int s = 0;
  for (; x; x -= x & -x) s += c[x];
  return s;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s);
    int len = strlen(s);
    l[i] = tot + 1;
    for (int j = 0; j < len; ++j) p[++tot] = s[j] - 'a';
    p[++tot] = 26 + i;
    r[i] = tot;
  }
  buildSA(tot);
  for (int i = 1; i <= n; ++i) {
    int pl = 1, pr = tot;
    for (int j = l[i]; j < r[i]; ++j) {
      int ql = query(pl, pr, p[j], j - l[i] + 1);
      int qr = query(pl, pr, p[j] + 1, j - l[i] + 1) - 1;
      pl = ql;
      pr = qr;
    }
    sl[i] = pl, sr[i] = pr;
  }
  for (int i = 1; i <= q; ++i) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    qr[r].push_back(make_pair(k, i)), qr[l - 1].push_back(make_pair(k, -i));
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = l[i]; j < r[i]; ++j) add(rk[j], 1);
    for (auto p : qr[i]) {
      int id = p.second, w = 1;
      if (id < 0) w = -1, id *= -1;
      ans[id] += w * (query(sr[p.first]) - query(sl[p.first] - 1));
    }
  }
  for (int i = 1; i <= q; ++i) {
    printf("%d\n", ans[i]);
  }
}
