#include <bits/stdc++.h>
using namespace std;
string s[200010];
struct ac {
  int fail;
  int son[26];
  int islast;
  int cnt;
  int fa;
} tree[200010];
int tot;
int cnt;
int head[200010];
int nxt[400010];
int to[400010];
void add(int x, int y) {
  to[++cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
}
vector<int> ed[200010];
int last[200010];
void build(string s, int id) {
  int l = s.length();
  int rt = 0;
  for (int i = 0; i < l; i++) {
    if (!tree[rt].son[s[i] - 'a']) {
      tree[rt].son[s[i] - 'a'] = ++tot;
      tree[tot].fa = rt;
      add(rt, tot);
    }
    rt = tree[rt].son[s[i] - 'a'];
  }
  ed[rt].push_back(id);
  last[id] = rt;
}
vector<int> g[200010];
void bfs() {
  queue<int> q;
  int rt = 0;
  for (int i = 0; i < 26; i++) {
    if (tree[rt].son[i]) {
      q.push(tree[rt].son[i]);
    }
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      if (tree[now].son[i]) {
        tree[tree[now].son[i]].fail = tree[tree[now].fail].son[i];
        q.push(tree[now].son[i]);
      } else {
        tree[now].son[i] = tree[tree[now].fail].son[i];
      }
    }
  }
  for (int i = 1; i <= tot; i++) {
    g[tree[i].fail].push_back(i);
  }
}
int Tree[200010];
int lowbit(int x) { return x & (-x); }
int dfn[200010];
int tt;
int size[200010];
void update(int x, int val) {
  for (int i = x; i <= tt; i += lowbit(i)) {
    Tree[i] += val;
  }
}
int query(int x) {
  if (!x) {
    return 0;
  }
  int ans = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) {
    ans += Tree[i];
  }
  return ans;
}
void dfs(int x) {
  size[x] = 1;
  dfn[x] = ++tt;
  for (int i = 0; i < g[x].size(); i++) {
    dfs(g[x][i]);
    size[x] += size[g[x][i]];
  }
}
vector<int> que[200010];
struct ques {
  int pos;
  int tag;
  int id;
  int ans;
} a[1000010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    build(s[i], i);
  }
  bfs();
  for (int i = 1; i <= m; i++) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    a[i].pos = r;
    a[i].tag = k;
    a[i + m].pos = l - 1;
    a[i + m].tag = k;
    a[i].id = i;
    a[i + m].id = i + m;
    que[r].push_back(i);
    que[l - 1].push_back(i + m);
  }
  dfs(0);
  for (int i = 1; i <= n; i++) {
    int rt = 0;
    int l = s[i].length();
    for (int j = 0; j < l; j++) {
      rt = tree[rt].son[s[i][j] - 'a'];
      update(dfn[rt], 1);
    }
    for (int j = 0; j < que[i].size(); j++) {
      a[que[i][j]].ans = query(dfn[last[a[que[i][j]].tag]] +
                               size[last[a[que[i][j]].tag]] - 1) -
                         query(dfn[last[a[que[i][j]].tag]] - 1);
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", a[i].ans - a[i + m].ans);
  }
  return 0;
}
