#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 500;
struct Node {
  int len, ch[26], fa;
} a[N];
char st[N];
int root[N], cur, node_cnt, seg_node, ch[N << 4][2], s[N << 4], pos[N], to[N],
    n, qn, fst[N], nxt[N], mm;
void ade(int u, int v) { to[++mm] = v, nxt[mm] = fst[u], fst[u] = mm; }
void update(int &rot, int lt, int rt, int q) {
  if (!rot) rot = ++seg_node;
  s[rot]++;
  if (lt == rt) return;
  int mid = (lt + rt) >> 1;
  if (q <= mid)
    update(ch[rot][0], lt, mid, q);
  else
    update(ch[rot][1], mid + 1, rt, q);
}
void ins(int ch, int id) {
  int u = cur;
  if (a[u].ch[ch]) {
    int v = a[u].ch[ch];
    if (a[v].len == a[u].len + 1) {
      cur = v;
      update(root[v], 1, n, id);
      return;
    }
    int t = ++node_cnt;
    update(root[t], 1, n, id);
    a[t] = a[v];
    a[t].len = a[u].len + 1;
    cur = a[v].fa = t;
    for (; u && a[u].ch[ch] == v; u = a[u].fa) a[u].ch[ch] = t;
    return;
  }
  cur = ++node_cnt;
  a[cur].len = a[u].len + 1;
  update(root[cur], 1, n, id);
  for (; u && !a[u].ch[ch]; u = a[u].fa) a[u].ch[ch] = cur;
  if (!u) {
    a[cur].fa = 1;
    return;
  }
  int v = a[u].ch[ch];
  if (a[v].len == a[u].len + 1) {
    a[cur].fa = v;
    return;
  }
  int t = ++node_cnt;
  a[t] = a[v];
  a[t].len = a[u].len + 1;
  a[cur].fa = a[v].fa = t;
  for (; u && a[u].ch[ch] == v; u = a[u].fa) a[u].ch[ch] = t;
}
int merge(int u, int v) {
  if (!u || !v) return u | v;
  int rot = ++seg_node;
  ch[rot][0] = merge(ch[u][0], ch[v][0]);
  ch[rot][1] = merge(ch[u][1], ch[v][1]);
  s[rot] = s[u] + s[v];
  return rot;
}
int query(int rot, int lt, int rt, int lq, int rq) {
  if (!rot) return 0;
  if (lt >= lq && rt <= rq) return s[rot];
  int mid = (lt + rt) >> 1;
  if (rq <= mid) return query(ch[rot][0], lt, mid, lq, rq);
  if (lq > mid) return query(ch[rot][1], mid + 1, rt, lq, rq);
  return query(ch[rot][0], lt, mid, lq, mid) +
         query(ch[rot][1], mid + 1, rt, mid + 1, rq);
}
void dfs(int u) {
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = to[i];
    dfs(v);
    root[u] = merge(root[u], root[v]);
  }
}
int main() {
  scanf("%d%d", &n, &qn);
  node_cnt = 1;
  for (int i = 1; i <= n; i++) {
    cur = 1;
    scanf("%s", st + 1);
    int len = strlen(st + 1);
    for (int j = 1; j <= len; j++) ins(st[j] - 97, i);
    pos[i] = cur;
  }
  for (int i = 2; i <= node_cnt; i++) ade(a[i].fa, i);
  dfs(1);
  for (int i = 1, l, r, q; i <= qn; i++) {
    scanf("%d%d%d", &l, &r, &q);
    printf("%d\n", query(root[pos[q]], 1, n, l, r));
  }
}
