#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[1000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 40;
const int maxn = 1e5 + 10;
const int base = 29;
const int mod = 1e9 + 7;
const int INF = 1e9 + 100;
const int SQ = 317;
string s[maxn];
int nxt[maxn][26];
int f[maxn];
int cur;
int cnt[maxn];
vector<int> g[maxn];
inline void insert(string &s) {
  int node = 0;
  for (auto ch : s) {
    int need = ch - 'a';
    if (!nxt[node][need]) nxt[node][need] = ++cur;
    node = nxt[node][need];
  }
  cnt[node]++;
}
int q[maxn];
inline void dfs(int v) {
  for (auto u : g[v]) {
    cnt[u] += cnt[v];
    dfs(u);
  }
}
inline void aho() {
  int h = 0, t = 0;
  for (int i = 0; i < 26; i++) {
    if (nxt[0][i]) q[t++] = nxt[0][i];
  }
  while (h < t) {
    int v = q[h++];
    for (int i = 0; i < 26; i++) {
      if (nxt[v][i]) {
        f[nxt[v][i]] = nxt[f[v]][i];
        q[t++] = nxt[v][i];
      } else {
        nxt[v][i] = nxt[f[v]][i];
      }
    }
  }
  for (int i = 1; i <= cur; i++) g[f[i]].push_back(i);
  dfs(0);
}
int res[maxn][SQ];
int kmp[maxn];
long long ret;
inline int KMP(string &pattern, string &s) {
  int pt = 0;
  int ret = 0;
  for (int i = 1; i < pattern.size(); i++) {
    while (pt && pattern[pt] != pattern[i]) pt = kmp[pt - 1];
    if (pattern[pt] == pattern[i]) pt++;
    kmp[i] = pt;
  }
  pt = 0;
  for (int i = 0; i < s.size(); i++) {
    while (pt && (pt == pattern.size() || s[i] != pattern[pt]))
      pt = kmp[pt - 1];
    if (s[i] == pattern[pt]) pt++;
    if (pt == pattern.size()) ret++;
  }
  return ret;
}
int sq;
int32_t main() {
  int n = in(), q = in();
  for (int i = 0; i < n; i++) s[i] = get();
  if (n < SQ)
    sq = 1;
  else
    sq = sqrt(n);
  for (int i = 0; i + sq - 1 < n; i += sq) {
    int part = i / sq;
    for (int j = 0; j < maxn; j++) g[j].clear();
    cur = 0;
    memset(nxt, 0, sizeof nxt);
    memset(cnt, 0, sizeof cnt);
    memset(f, 0, sizeof f);
    for (int j = i; j < i + sq; j++) insert(s[j]);
    aho();
    for (int j = 0; j < n; j++) {
      int node = 0;
      for (auto ch : s[j]) {
        int need = ch - 'a';
        node = nxt[node][need];
        res[j][part] += cnt[node];
      }
    }
  }
  while (q--) {
    int l = in() - 1, r = in() - 1, k = in() - 1;
    ret = 0;
    while (l <= r) {
      if (l % sq == 0 && l + sq - 1 <= r) {
        ret += res[k][l / sq];
        l += sq;
      } else
        ret += KMP(s[l++], s[k]);
    }
    printf("%lld\n", ret);
  }
}
