#include <bits/stdc++.h>
using namespace std;
const int N = 200020;
int ch[N * 2][26], fa[N * 2], len[N * 2], tot = 1;
int insert(int last, int c) {
  if (len[ch[last][c]] == len[last] + 1) return ch[last][c];
  int np = ++tot, p = last;
  len[np] = len[last] + 1;
  while (p && !ch[p][c]) ch[p][c] = np, p = fa[p];
  if (!p) {
    fa[np] = 1;
    return np;
  }
  int q = ch[p][c];
  if (len[p] + 1 == len[q]) {
    fa[np] = q;
    return np;
  }
  int nq = ++tot, ret = (p == last) ? nq : np;
  len[nq] = len[p] + 1, fa[nq] = fa[q], memcpy(ch[nq], ch[q], sizeof(ch[q]));
  fa[np] = fa[q] = nq;
  while (p && ch[p][c] == q) ch[p][c] = nq, p = fa[p];
  return ret;
}
int n, m, pos[N];
char str[N];
int rt[N * 2], ls[N * 30], rs[N * 30], sum[N * 30], cnt;
void ins(int &rt, int l, int r, int pos) {
  if (!rt) rt = ++cnt;
  sum[rt]++;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    ins(ls[rt], l, mid, pos);
  else
    ins(rs[rt], mid + 1, r, pos);
}
int ask(int &rt, int l, int r, int ql, int qr) {
  if (!rt) return 0;
  if (ql <= l && r <= qr) return sum[rt];
  int mid = (l + r) >> 1, ans = 0;
  if (ql <= mid) ans += ask(ls[rt], l, mid, ql, qr);
  if (qr > mid) ans += ask(rs[rt], mid + 1, r, ql, qr);
  return ans;
}
int merge(int x, int y) {
  if (!x || !y) return x | y;
  int rt = ++cnt;
  ls[rt] = merge(ls[x], ls[y]);
  rs[rt] = merge(rs[x], rs[y]);
  sum[rt] = sum[x] + sum[y];
  return rt;
}
template <typename _T>
inline void read(_T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') f |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
  if (f) x = -x;
}
vector<int> son[N * 2];
void dfs(int x) {
  for (int i = 0; i < son[x].size(); ++i) {
    int y = son[x][i];
    dfs(y), rt[x] = merge(rt[x], rt[y]);
  }
}
void prepare() {
  for (int i = 2; i <= tot; ++i) son[fa[i]].push_back(i);
  dfs(1);
}
template <typename _T>
inline void write(_T x) {
  char s[30] = {}, *p = s + 27;
  if (x < 0) putchar('-'), x = -x;
  do *(--p) = x % 10 + '0', x /= 10;
  while (x);
  puts(p);
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str);
    int last = 1;
    for (int j = 0; str[j]; ++j) {
      last = insert(last, str[j] - 'a');
      ins(rt[last], 1, n, i);
    }
    pos[i] = last;
  }
  prepare();
  while (m--) {
    int l, r, k;
    read(l), read(r), read(k);
    write(ask(rt[pos[k]], 1, n, l, r));
  }
  return 0;
}
