#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch = getchar();
  int x = 0, pd = 0;
  while (ch < '0' || ch > '9') pd |= ch == '-', ch = getchar();
  while ('0' <= ch && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return pd ? -x : x;
}
const int maxn = 200005;
int n, m;
char temp[maxn];
string data[maxn];
int tot, ch[maxn][26], edp[maxn];
void insert(char *s, int k) {
  int r = 0, d, len = strlen(s);
  for (int i = 0; i < len; i++) {
    data[k] += s[i];
    d = s[i] - 'a';
    if (!ch[r][d]) ch[r][d] = ++tot;
    r = ch[r][d];
  }
  edp[k] = r;
}
int fail[maxn];
void build() {
  queue<int> q;
  for (int i = 0; i < 26; i++)
    if (ch[0][i]) q.push(ch[0][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      int v = ch[u][i];
      if (!v)
        ch[u][i] = ch[fail[u]][i];
      else {
        fail[v] = ch[fail[u]][i];
        q.push(v);
      }
    }
  }
}
int e, bg[maxn], to[maxn], nx[maxn];
void link(int u, int v) { to[++e] = v, nx[e] = bg[u], bg[u] = e; }
int cnt, L[maxn], R[maxn];
void dfs(int u) {
  L[u] = ++cnt;
  for (int i = bg[u]; i; i = nx[i]) dfs(to[i]);
  R[u] = cnt;
}
int root[maxn], ls[maxn << 5], rs[maxn << 5], sum[maxn << 5], N;
void update(int pre, int &rt, int l, int r, int x) {
  rt = ++N, ls[rt] = ls[pre], rs[rt] = rs[pre], sum[rt] = sum[pre] + 1;
  if (l == r) return;
  int mid = l + r >> 1;
  if (x <= mid)
    update(ls[pre], ls[rt], l, mid, x);
  else
    update(rs[pre], rs[rt], mid + 1, r, x);
}
int query(int pre, int rt, int l, int r, int L, int R) {
  if (L <= l && r <= R) return sum[rt] - sum[pre];
  int mid = l + r >> 1;
  if (R <= mid) return query(ls[pre], ls[rt], l, mid, L, R);
  if (L > mid) return query(rs[pre], rs[rt], mid + 1, r, L, R);
  return query(ls[pre], ls[rt], l, mid, L, R) +
         query(rs[pre], rs[rt], mid + 1, r, L, R);
}
void add(char *s, int k) {
  int r = 0, len = strlen(s);
  for (int i = 0; i < len; i++)
    r = ch[r][s[i] - 'a'], update(root[k], root[k], 1, cnt, L[r]);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", temp);
    insert(temp, i);
  }
  build();
  for (int i = 1; i <= tot; i++) link(fail[i], i);
  dfs(0);
  for (int i = 1; i <= n; i++) root[i] = root[i - 1], add(&data[i][0], i);
  while (m--) {
    int x = read(), y = read(), z = read();
    printf("%d\n", query(root[x - 1], root[y], 1, cnt, L[edp[z]], R[edp[z]]));
  }
  return 0;
}
