#include <bits/stdc++.h>
using namespace std;
inline int Read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int first[500005], nxt[500005], to[500005], Tot;
void Add(int x, int y) {
  nxt[++Tot] = first[x];
  first[x] = Tot;
  to[Tot] = y;
}
int Trie[200005][26], fail[200005], End[200005], fa[200005], ans[500005],
    dfn[200005], c[200005], tot, ind;
int sz[200005];
char s[200005];
struct que {
  int pos, val, opt, id;
  bool operator<(que A) const { return pos < A.pos; }
} q[1000005];
void build(int x) {
  int len = strlen(s + 1), nw = 0;
  for (int i = 1; i <= len; i++) {
    if (!Trie[nw][s[i] - 'a']) Trie[nw][s[i] - 'a'] = ++tot, fa[tot] = nw;
    nw = Trie[nw][s[i] - 'a'];
  }
  End[x] = nw;
}
void getfail() {
  queue<int> q;
  for (int i = 0; i < 26; i++)
    if (Trie[0][i]) fail[Trie[0][i]] = 0, q.push(Trie[0][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      if (Trie[u][i])
        fail[Trie[u][i]] = Trie[fail[u]][i], q.push(Trie[u][i]);
      else
        Trie[u][i] = Trie[fail[u]][i];
    }
  }
}
void dfs(int u, int fa) {
  dfn[u] = ++ind;
  sz[u] = 1;
  for (int e = first[u]; e; e = nxt[e]) {
    int v = to[e];
    if (v == fa) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
}
int lowbit(int x) { return x & (-x); }
void modify(int x, int val) {
  for (int i = x; i <= tot + 1; i += lowbit(i)) c[i] += val;
}
int query(int x) {
  int res = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) res += c[i];
  return res;
}
signed main() {
  int n = Read(), m = Read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    build(i);
  }
  getfail();
  for (int i = 1; i <= tot; i++) Add(fail[i], i);
  for (int i = 1; i <= m; i++) {
    int l = Read(), r = Read(), k = Read();
    q[i * 2 - 1] = (que){l - 1, k, -1, i};
    q[i * 2] = (que){r, k, 1, i};
  }
  sort(q + 1, q + 2 * m + 1);
  dfs(0, 0);
  int pos = 1;
  for (int i = 0; i <= n; i++) {
    int xx = End[i];
    while (xx) modify(dfn[xx], 1), xx = fa[xx];
    while (pos <= 2 * m && q[pos].pos == i)
      ans[q[pos].id] +=
          q[pos].opt * (query(dfn[End[q[pos].val]] + sz[End[q[pos].val]] - 1) -
                        query(dfn[End[q[pos].val]] - 1)),
          ++pos;
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
