#include <bits/stdc++.h>
using namespace std;
inline int Rd() {
  int s = 0;
  char fl = 0, c = getchar();
  while (c < '0' || c > '9') fl |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return fl ? -s : s;
}
const int N = 2e5 + 5;
int tot;
int ch[N][26], fail[N], p[N];
char c[N];
inline void Insert(int pos) {
  int x = 0, siz = strlen(c);
  for (int i = 0; i < siz; ++i) {
    int w = c[i] - 'a';
    if (!ch[x][w]) ch[x][w] = ++tot;
    x = ch[x][w];
  }
  p[pos] = x;
}
int cnt, to[N], nxt[N], h[N];
inline void AddEdge(int x, int y) {
  to[++cnt] = y, nxt[cnt] = h[x], h[x] = cnt;
}
inline void Build_AC() {
  queue<int> Q;
  for (int i = 0; i < 26; ++i)
    if (ch[0][i]) Q.push(ch[0][i]);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < 26; ++i) {
      if (ch[x][i])
        fail[ch[x][i]] = ch[fail[x]][i], Q.push(ch[x][i]);
      else
        ch[x][i] = ch[fail[x]][i];
    }
  }
  for (int i = 1; i <= tot; ++i) AddEdge(fail[i], i);
}
int sign, in[N], out[N];
inline void DFS(int x) {
  in[x] = ++sign;
  for (int i = h[x]; i; i = nxt[i]) DFS(to[i]);
  out[x] = sign;
}
int C[N];
inline void Add(int x, int d) {
  for (int i = x; i <= sign; i += i & -i) C[i] += d;
}
inline int Ask(int x) {
  int res = 0;
  for (int i = x; i; i -= i & -i) res += C[i];
  return res;
}
inline int Query(int l, int r) { return Ask(r) - Ask(l - 1); }
inline void Addval(string c) {
  int x = 0, siz = c.size();
  for (int i = 0; i < siz; ++i) x = ch[x][c[i] - 'a'], Add(in[x], 1);
}
const int M = 5e5 + 5;
struct Que {
  int typ, id, k;
};
vector<Que> vec[N];
int ans[M];
int n, Q;
string s[N];
int main() {
  n = Rd(), Q = Rd();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", c);
    s[i] = c;
    Insert(i);
  }
  Build_AC();
  DFS(0);
  for (int i = 1; i <= Q; ++i) {
    int l = Rd(), r = Rd(), k = Rd();
    if (l > 1) vec[l - 1].push_back((Que){-1, i, k});
    vec[r].push_back((Que){1, i, k});
  }
  for (int i = 1; i <= n; ++i) {
    Addval(s[i]);
    for (int j = 0, siz = vec[i].size(); j < siz; ++j) {
      Que tmp = vec[i][j];
      int x = p[tmp.k];
      ans[tmp.id] += tmp.typ * Query(in[x], out[x]);
    }
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}
