#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long BIG = 1446803456761533460LL;
const int Big = 336860180;
const int INF = INT_MAX;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int powMod(int a, int b) {
  int n = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      n = (n * (a)) % MOD;
    }
    a = (a * (a)) % MOD;
    b /= 2;
  }
  return n;
}
int modularInverse(int a) { return powMod(a, MOD - 2); }
stringstream sss;
const int maxn = 100010;
const int SQ = 500;
const int E = 26;
int n, Q;
string Si[maxn];
int node[maxn];
int nn = 1;
int C[maxn][E], F[maxn];
queue<int> q;
vector<int> subt[maxn];
int st[maxn], ft[maxn], tim = 0;
int Aho_log[SQ][maxn];
int fen[maxn];
int S2I[maxn];
vector<pair<int, int> > qBigL[maxn], qBigR[maxn];
vector<pair<int, int> > qSmlL[maxn], qSmlR[maxn];
long long smBig[maxn];
long long res[maxn];
int add_string(string s) {
  int x = 0;
  for (auto c : s) {
    c -= 'a';
    if (!C[x][c]) {
      C[x][c] = nn++;
    }
    x = C[x][c];
  }
  return x;
}
void Aho() {
  for (int e = (0); e < (E); ++e) {
    if (C[0][e]) {
      q.push(C[0][e]);
      subt[0].push_back(C[0][e]);
    }
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int e = (0); e < (E); ++e) {
      if (C[x][e]) {
        F[C[x][e]] = C[F[x]][e];
        subt[C[F[x]][e]].push_back(C[x][e]);
        q.push(C[x][e]);
      } else {
        C[x][e] = C[F[x]][e];
      }
    }
  }
}
void dfs_stft(int x) {
  st[x] = tim++;
  for (auto y : subt[x]) {
    dfs_stft(y);
  }
  ft[x] = tim;
}
void update(int i, int v) {
  for (++i; i < maxn; i += i & (-i)) fen[i] += v;
}
int get(int i) {
  int s = 0;
  for (++i; i > 0; i -= i & (-i)) s += fen[i];
  return s;
}
void MAIN() {
  cin >> n >> Q;
  for (int i = (0); i < (n); ++i) {
    cin >> Si[i];
    node[i] = add_string(Si[i]);
  }
  Aho();
  dfs_stft(0);
  for (int q = (0); q < (Q); ++q) {
    int l, r, k;
    cin >> l >> r >> k;
    --l, --r, --k;
    if (Si[k].size() > SQ) {
      qBigL[l].push_back({k, q});
      qBigR[r].push_back({k, q});
    } else {
      qSmlL[l].push_back({k, q});
      qSmlR[r].push_back({k, q});
    }
  }
  int ii = 0;
  for (int i = (0); i < (n); ++i) {
    if (Si[i].size() > SQ) {
      S2I[i] = ii;
      int x = 0;
      for (auto c : Si[i]) {
        x = C[x][c - 'a'];
        Aho_log[ii][st[x] + 1]++;
      }
      for (int j = (0); j < (nn + 1); ++j) {
        Aho_log[ii][j + 1] += Aho_log[ii][j];
      }
      ++ii;
    }
  }
  for (int i = (0); i < (n); ++i) {
    for (auto q : qBigL[i]) {
      res[q.second] -= smBig[S2I[q.first]];
    }
    for (int j = (0); j < (ii); ++j) {
      smBig[j] += Aho_log[j][ft[node[i]]] - Aho_log[j][st[node[i]]];
    }
    for (auto q : qBigR[i]) {
      res[q.second] += smBig[S2I[q.first]];
    }
  }
  for (int i = (0); i < (n); ++i) {
    for (auto q : qSmlL[i]) {
      int x = 0;
      for (auto c : Si[q.first]) {
        x = C[x][c - 'a'];
        res[q.second] -= get(st[x]);
      }
    }
    update(st[node[i]], 1);
    update(ft[node[i]], -1);
    for (auto q : qSmlR[i]) {
      int x = 0;
      for (auto c : Si[q.first]) {
        x = C[x][c - 'a'];
        res[q.second] += get(st[x]);
      }
    }
  }
  for (int i = (0); i < (Q); ++i) {
    cout << (res[i]) << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
5 5
a
ab
abab
ababab
b
1 5 4
3 5 4
1 5 2
1 5 3
1 4 1
    )";
  MAIN();
  return 0;
}
