#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005, Maxq = 500005;
int cnt = 1, st[Maxn], ed[Maxn], pos[Maxn], c[Maxn], ans[Maxq];
char s[Maxn];
string buf[Maxn];
vector<int> son[Maxn];
vector<tuple<int, int, int>> vec[Maxn];
struct node {
  int son[26], fail;
} w[Maxn];
int lowbit(int x) { return x & -x; }
void Modify(int x, int val) {
  for (int i = x; i <= cnt; i += lowbit(i)) c[i] += val;
}
int Ask(int x) {
  int ans = 0;
  for (int i = x; i; i -= lowbit(i)) ans += c[i];
  return ans;
}
int Insert() {
  int p = 1;
  for (int i = 1; s[i]; i++) {
    int t = s[i] - 'a';
    if (!w[p].son[t]) w[p].son[t] = ++cnt;
    p = w[p].son[t];
  }
  return p;
}
void Build() {
  queue<int> Q;
  Q.push(1);
  while (Q.size()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < 26; i++)
      if (int y = w[x].son[i]) {
        int t = w[x].fail;
        while (t && !w[t].son[i]) t = w[t].fail;
        if (t)
          w[y].fail = w[t].son[i];
        else
          w[y].fail = 1;
        Q.push(y);
      }
  }
}
void dfs(int x) {
  static int cnt;
  st[x] = ++cnt;
  for (int y : son[x]) dfs(y);
  ed[x] = cnt;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    buf[i] = s + 1;
    pos[i] = Insert();
  }
  Build();
  for (int i = 1; i <= cnt; i++) son[w[i].fail].push_back(i);
  dfs(1);
  for (int i = 1; i <= q; i++) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    vec[r].emplace_back(k, i, 1);
    vec[l - 1].emplace_back(k, i, -1);
  }
  for (int i = 1; i <= n; i++) {
    for (size_t p = 1, j = 0; j < buf[i].size(); j++)
      p = w[p].son[buf[i][j] - 'a'], Modify(st[p], 1);
    for (auto& e : vec[i]) {
      int k, id, type;
      tie(k, id, type) = e;
      ans[id] += type * (Ask(ed[pos[k]]) - Ask(st[pos[k]] - 1));
    }
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}
