#include <bits/stdc++.h>
using namespace std;
char ST;
char *s[200005], S[200005];
int n, q, slen[200005], pos[200005], rt[200005];
int last, tr[200005 << 1][26], fa[200005 << 1], len[200005 << 1], tot;
int lc[200005 * 20], rc[200005 * 20], sm[200005 * 20], cnt;
void ins(int c) {
  int p, q;
  if (tr[last][c]) {
    p = last;
    if (len[q = tr[p][c]] != len[p] + 1) {
      int cl = ++tot;
      memcpy(tr[cl], tr[q], sizeof tr[q]);
      fa[cl] = fa[q], len[cl] = len[p] + 1;
      for (; p != -1 && tr[p][c] == q; tr[p][c] = cl, p = fa[p])
        ;
      fa[q] = cl;
    }
  } else {
    int cur = ++tot;
    len[cur] = len[p = last] + 1;
    for (; p != -1 && !tr[p][c]; tr[p][c] = cur, p = fa[p])
      ;
    if (p == -1)
      fa[cur] = 0;
    else if (len[q = tr[p][c]] == len[p] + 1)
      fa[cur] = q;
    else {
      int cl = ++tot;
      memcpy(tr[cl], tr[q], sizeof tr[q]);
      fa[cl] = fa[q], len[cl] = len[p] + 1;
      for (; p != -1 && tr[p][c] == q; tr[p][c] = cl, p = fa[p])
        ;
      fa[q] = fa[cur] = cl;
    }
  }
}
void ins(int &u, int l, int r, int p) {
  lc[++cnt] = lc[u], rc[cnt] = rc[u], sm[cnt] = sm[u] + 1;
  u = cnt;
  if (l == r) return;
  int m = l + r >> 1;
  p <= m ? ins(lc[u], l, m, p) : ins(rc[u], m + 1, r, p);
}
int qry(int u, int l, int r, int ql, int qr) {
  if (l > qr || ql > r || ql > qr || !u) return 0;
  if (ql <= l && r <= qr) return sm[u];
  int m = l + r >> 1;
  return qry(lc[u], l, m, ql, qr) + qry(rc[u], m + 1, r, ql, qr);
}
vector<int> G[200005 << 1];
int st[200005 << 1], ed[200005 << 1], tim;
void dfs(int u) {
  st[u] = ++tim;
  for (int v : G[u]) dfs(v);
  ed[u] = tim;
}
char ED;
int main() {
  scanf("%d%d", &n, &q);
  fa[0] = -1;
  for (int i = (1), LIM = (n); i <= LIM; i++) {
    scanf("%s", S);
    slen[i] = strlen(S);
    s[i] = new char[slen[i] + 1];
    memcpy(s[i], S, sizeof(char) * slen[i]);
    last = 0;
    for (int j = (0), LIM = (slen[i] - 1); j <= LIM; j++)
      ins(s[i][j] - 'a'), last = tr[last][s[i][j] - 'a'];
  }
  for (int i = (1), LIM = (tot); i <= LIM; i++) G[fa[i]].push_back(i);
  dfs(0);
  for (int i = (1), LIM = (n); i <= LIM; i++) {
    rt[i] = rt[i - 1];
    for (int j = (0), LIM = (slen[i] - 1); j <= LIM; j++)
      pos[i] = tr[pos[i]][s[i][j] - 'a'], ins(rt[i], 1, tot + 1, st[pos[i]]);
  }
  for (int l, r, K; q--;) {
    scanf("%d%d%d", &l, &r, &K);
    printf("%d\n", qry(rt[r], 1, tot + 1, st[pos[K]], ed[pos[K]]) -
                       qry(rt[l - 1], 1, tot + 1, st[pos[K]], ed[pos[K]]));
  }
}
