#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100000;
const int MAXLEN = 100000;
const int MAXX = 1 + MAXLEN;
const int MINLONGLEN = 707;
const int MAXQ = 100000;
const int STEP = 316;
typedef struct X {
  int nxt[26];
  int endhead, par, childhead, childnxt, d, prefhead;
} X;
int n, nq;
char s[MAXLEN + 1];
int pos[MAXN + 1], len[MAXN], id[MAXLEN];
X x[MAXX];
int root, nx;
int endnxt[MAXN];
int prefnxt[MAXLEN];
int getx(int d) {
  for (int k = (0); k < (26); ++k) x[nx].nxt[k] = -1;
  x[nx].endhead = x[nx].par = x[nx].childhead = x[nx].childnxt =
      x[nx].prefhead = -1;
  x[nx].d = d;
  return nx++;
}
bool ispref[MAXX];
long long cnt[MAXN + 1], sum[MAXN + 1];
int qhead[MAXN];
int qnxt[MAXQ], ql[MAXQ], qr[MAXQ];
long long ret[MAXQ];
int qqhead, qqtail, qq[MAXX];
int dfs1(int at, int want) {
  int ret = 0;
  for (int z = x[at].prefhead; z != -1; z = prefnxt[z])
    if (id[z] == want) ++ret;
  for (int z = x[at].childhead; z != -1; z = x[z].childnxt)
    ret += dfs1(z, want);
  for (int z = x[at].endhead; z != -1; z = endnxt[z]) cnt[z + 1] += ret;
  return ret;
}
void inc(int pos, int by) {
  while (pos % STEP != 0) cnt[pos] += by, ++pos;
  while (pos <= n) sum[pos] += by, pos += STEP;
}
long long get(int pos) { return cnt[pos] + sum[pos - pos % STEP]; }
void dfs2(int at) {
  for (int z = x[at].endhead; z != -1; z = endnxt[z]) inc(z + 1, +1);
  for (int z = x[at].childhead; z != -1; z = x[z].childnxt) dfs2(z);
  for (int z = x[at].prefhead; z != -1; z = prefnxt[z])
    if (len[id[z]] < MINLONGLEN)
      for (int zz = qhead[id[z]]; zz != -1; zz = qnxt[zz])
        ret[zz] += get(qr[zz]) - get(ql[zz]);
  for (int z = x[at].endhead; z != -1; z = endnxt[z]) inc(z + 1, -1);
}
void printtree(int at, int d) {
  if (d > 10) return;
  for (int k = (0); k < (26); ++k)
    if (x[at].nxt[k] != -1 && x[x[at].nxt[k]].d > x[at].d) {
      for (int i = (0); i < (d); ++i) printf("  ");
      printf("%c->%d [%d]\n", 'a' + k, x[at].nxt[k], x[x[at].nxt[k]].par);
      printtree(x[at].nxt[k], d + 1);
    }
}
void run() {
  scanf("%d%d", &n, &nq);
  pos[0] = 0;
  for (int i = (0); i < (n); ++i) {
    scanf("%s", s + pos[i]);
    len[i] = strlen(s + pos[i]);
    pos[i + 1] = pos[i] + len[i];
  }
  s[pos[n]] = '\0';
  nx = 0;
  root = getx(0);
  for (int i = (0); i < (n); ++i) {
    int at = root;
    for (int j = (0); j < (len[i]); ++j) {
      int k = s[pos[i] + j] - 'a';
      if (x[at].nxt[k] == -1) x[at].nxt[k] = getx(x[at].d + 1);
      at = x[at].nxt[k];
      prefnxt[pos[i] + j] = x[at].prefhead;
      x[at].prefhead = pos[i] + j;
      id[pos[i] + j] = i;
    }
    endnxt[i] = x[at].endhead;
    x[at].endhead = i;
  }
  qqhead = qqtail = 0;
  for (int k = (0); k < (26); ++k)
    if (x[root].nxt[k] == -1)
      x[root].nxt[k] = root;
    else
      qq[qqhead++] = x[root].nxt[k], x[x[root].nxt[k]].par = root;
  while (qqtail < qqhead) {
    int at = qq[qqtail++];
    for (int k = (0); k < (26); ++k)
      if (x[at].nxt[k] != -1) {
        qq[qqhead++] = x[at].nxt[k];
        x[x[at].nxt[k]].par = x[x[at].par].nxt[k];
      } else {
        x[at].nxt[k] = x[x[at].par].nxt[k];
      }
  }
  for (int i = (0); i < (nx); ++i)
    if (x[i].par != -1) {
      x[i].childnxt = x[x[i].par].childhead;
      x[x[i].par].childhead = i;
    }
  for (int i = (0); i < (n); ++i) qhead[i] = -1;
  for (int i = (0); i < (nq); ++i) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    --l, --k;
    qnxt[i] = qhead[k];
    qhead[k] = i;
    ql[i] = l;
    qr[i] = r;
  }
  for (int i = (0); i < (nq); ++i) ret[i] = 0;
  for (int i = (0); i < (n); ++i)
    if (len[i] >= MINLONGLEN) {
      memset(cnt, 0, sizeof(cnt));
      dfs1(root, i);
      for (int j = (0); j < (n); ++j) cnt[j + 1] += cnt[j];
      for (int z = qhead[i]; z != -1; z = qnxt[z])
        ret[z] += cnt[qr[z]] - cnt[ql[z]];
    }
  memset(cnt, 0, sizeof(cnt));
  memset(sum, 0, sizeof(sum));
  dfs2(root);
  for (int i = (0); i < (nq); ++i) printf("%I64d\n", ret[i]);
}
int main() {
  run();
  return 0;
}
