#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
template <class T>
inline void _read(T& x) {
  char ch = getchar();
  bool mark = false;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') mark = true;
  for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  if (mark) x = -x;
}
struct node {
  int Next[26], pre, fail;
} T[maxn];
int tot = 1;
void Build_AC_Automaton() {
  queue<int> Q;
  Q.push(1);
  int i, j;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (i = 0; i < 26; i++)
      if (T[x].Next[i]) {
        int v = T[x].Next[i];
        for (j = T[x].fail; j && !T[j].Next[i]; j = T[j].fail)
          ;
        T[v].fail = j ? T[j].Next[i] : 1;
        Q.push(v);
      }
  }
}
int n, qq;
struct query {
  int L, R, id;
  query(int L, int R, int id) : L(L), R(R), id(id) {}
};
vector<query> Q[maxn];
char s[maxn];
int lim, len[maxn], End[maxn], id[maxn];
vector<int> A[maxn], word[maxn], sons[maxn];
long long ans[maxn], f[maxn], sum[maxn];
void dfs(int x) {
  int i;
  for (i = 0; i < sons[x].size(); i++) {
    dfs(sons[x][i]);
    f[x] += f[sons[x][i]];
  }
  for (i = 0; i < word[x].size(); i++) sum[word[x][i]] += f[x];
}
void SolveLongWords() {
  for (int i = 1; i <= n; i++)
    if (len[i] > lim) {
      int j;
      memset(f, 0, sizeof(f));
      memset(sum, 0, sizeof(sum));
      for (j = End[i]; j; j = T[j].pre) f[j] = 1;
      dfs(1);
      for (j = 2; j <= n; j++) sum[j] += sum[j - 1];
      for (j = 0; j < Q[i].size(); j++)
        ans[Q[i][j].id] = sum[Q[i][j].R] - sum[Q[i][j].L - 1];
    }
}
int Sum[maxn], delta[maxn];
void Add(int x, int d) {
  for (int i = x; id[i] == id[x]; i++) Sum[i] += d;
  for (int i = id[x] + 1; i <= id[n]; i++) delta[i] += d;
}
int Query(int x) { return Sum[x] + delta[id[x]]; }
void DFS(int x) {
  int i, j;
  for (i = 0; i < word[x].size(); i++) Add(word[x][i], 1);
  for (i = 0; i < A[x].size(); i++) {
    int t = A[x][i];
    for (j = 0; j < Q[t].size(); j++)
      ans[Q[t][j].id] += Query(Q[t][j].R) - Query(Q[t][j].L - 1);
  }
  for (i = 0; i < sons[x].size(); i++) DFS(sons[x][i]);
  for (i = 0; i < word[x].size(); i++) Add(word[x][i], -1);
}
int main() {
  int i, j;
  _read(n);
  _read(qq);
  lim = (int)sqrt(n);
  for (i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    int cur = 1;
    len[i] = strlen(s + 1);
    for (j = 1; j <= len[i]; j++) {
      int x = s[j] - 'a';
      if (!T[cur].Next[x]) T[cur].Next[x] = ++tot, T[tot].pre = cur;
      cur = T[cur].Next[x];
      if (len[i] <= lim) A[cur].push_back(i);
    }
    End[i] = cur;
    word[cur].push_back(i);
  }
  Build_AC_Automaton();
  for (i = 1; i <= tot; i++) sons[T[i].fail].push_back(i);
  for (i = 1; i <= qq; i++) {
    int L, R, k;
    _read(L);
    _read(R);
    _read(k);
    Q[k].push_back(query(L, R, i));
  }
  SolveLongWords();
  for (i = 1; i <= n; i++) id[i] = (i - 1) / lim + 1;
  DFS(1);
  for (i = 1; i <= qq; i++) cout << ans[i] << endl;
  return 0;
}
