#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int head[maxn], to[maxn], ne[maxn];
int ch[maxn][26];
int fail[maxn];
int cot;
int ecot;
int l[maxn], r[maxn], dfs_cot;
long long c[maxn << 1];
void modify(int x, long long v) {
  for (int i = x; i <= dfs_cot; i += i & -i) c[i] += v;
}
long long query(int x) {
  long long ans = 0;
  for (int i = x; i > 0; i -= i & -i) ans += c[i];
  return ans;
}
int idx(char s) { return s - 'a'; }
void addedge(int u, int v) {
  to[ecot] = v;
  ne[ecot] = head[u];
  head[u] = ecot++;
}
int newnode() {
  for (int i = 0; i < 26; i++) {
    ch[cot][i] = -1;
  }
  return cot++;
}
void init() {
  memset(head, -1, sizeof(head));
  ecot = 0;
  dfs_cot = 0;
  cot = 0;
  newnode();
}
int add(char *T) {
  int n = strlen(T);
  int u = 0, p;
  for (int i = 0; i < n; i++) {
    p = idx(T[i]);
    if (ch[u][p] == -1) ch[u][p] = newnode();
    u = ch[u][p];
  }
  return u;
}
void build() {
  queue<int> q;
  fail[0] = 0;
  for (int i = 0; i < 26; i++) {
    if (ch[0][i] == -1)
      ch[0][i] = 0;
    else {
      q.push(ch[0][i]);
      fail[ch[0][i]] = 0;
      addedge(0, ch[0][i]);
    }
  }
  int u, p;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      if (ch[u][i] == -1)
        ch[u][i] = ch[fail[u]][i];
      else {
        q.push(ch[u][i]);
        fail[ch[u][i]] = ch[fail[u]][i];
        addedge(ch[fail[u]][i], ch[u][i]);
      }
    }
  }
}
void dfs(int u, int fa) {
  l[u] = ++dfs_cot;
  for (int i = head[u]; ~i; i = ne[i])
    if (to[i] != fa) dfs(to[i], u);
  r[u] = ++dfs_cot;
}
void scan(char *T) {
  int u = 0, n = strlen(T);
  for (int i = 0; i < n; i++) {
    u = ch[u][idx(T[i])];
    modify(l[u], 1LL);
  }
}
char str[maxn << 1];
int len;
int last[maxn];
vector<pair<int, int> > ql[maxn];
vector<pair<int, int> > qr[maxn];
long long ans[500005];
int main() {
  int n, m;
  init();
  scanf("%d %d", &n, &m);
  getchar();
  len = 0;
  for (int i = 0; i < n; i++) {
    while (1) {
      str[len++] = getchar();
      if (str[len - 1] == '\n') {
        str[len - 1] = '\0';
        break;
      }
    }
  }
  char *p = str;
  for (int i = 1; i <= n; i++) {
    last[i] = add(p);
    p += strlen(p) + 1;
  }
  build();
  dfs(0, -1);
  int L, R, Y;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &L, &R, &Y);
    ql[L].push_back(make_pair(i, Y));
    qr[R].push_back(make_pair(i, Y));
  }
  p = str;
  int temp;
  for (int i = 1; i <= n; i++) {
    scan(p);
    p += strlen(p) + 1;
    for (int j = 0; j < ql[i + 1].size(); j++) {
      temp = last[ql[i + 1][j].second];
      ans[ql[i + 1][j].first] -= query(r[temp]) - query(l[temp] - 1);
    }
    for (int j = 0; j < qr[i].size(); j++) {
      temp = last[qr[i][j].second];
      ans[qr[i][j].first] += query(r[temp]) - query(l[temp] - 1);
    }
  }
  for (int i = 0; i < m; i++) {
    printf("%I64d\n", ans[i]);
  }
  return 0;
}
