#include <bits/stdc++.h>
using namespace std;
int sq = 500;
vector<int> gr[100009];
string pattern[100009];
vector<pair<pair<int, int>, int> > que[100009];
int n;
struct aho {
  int f[100009], g[100009][26], sz;
  vector<int> out[100009], goin[100009], goinsq[100009];
  aho() {
    memset(g, -1, sizeof(g));
    memset(f, -1, sizeof(f));
    sz = 0;
  }
  void add_string(string &s, int id) {
    int cur_state = 0;
    for (int i = 0; i < s.size(); i++) {
      int ch = s[i] - 'a';
      if (g[cur_state][ch] == -1) {
        g[cur_state][ch] = (++sz);
      }
      cur_state = g[cur_state][ch];
      if (s.size() < sq) {
        goin[cur_state].push_back(id);
      }
      goinsq[cur_state].push_back(id);
    }
    out[cur_state].push_back(id);
  }
  void build_automaton() {
    queue<int> q;
    for (int i = 0; i < 26; i++) {
      if (g[0][i] != -1) {
        q.push(g[0][i]);
        f[g[0][i]] = 0;
        gr[f[g[0][i]]].push_back(g[0][i]);
      } else {
        g[0][i] = 0;
      }
    }
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (g[x][i] != -1) {
          q.push(g[x][i]);
          int fail = f[x];
          while (g[fail][i] == -1) {
            fail = f[fail];
          }
          f[g[x][i]] = g[fail][i];
          gr[f[g[x][i]]].push_back(g[x][i]);
        }
      }
    }
  }
};
aho tree;
long long subsize[100009], ans[100009];
void dfs(int pos, int prev, int id) {
  for (int i = 0; i < gr[pos].size(); i++) {
    if (gr[pos][i] != prev) {
      dfs(gr[pos][i], pos, id);
      subsize[pos] += subsize[gr[pos][i]];
    }
  }
  for (int i = 0; i < tree.goinsq[pos].size(); i++) {
    if (tree.goinsq[pos][i] == id) {
      subsize[pos]++;
    }
  }
  for (int i = 0; i < tree.out[pos].size(); i++) {
    ans[tree.out[pos][i]] = subsize[pos];
  }
}
long long ans1[2 * 100009], ans2[510][510];
inline void update(int pos, int val) {
  int block = pos / sq;
  int poss = pos;
  if (poss % sq != 0) {
    while (poss % sq != 0) {
      ans2[block][poss % sq] += val;
      poss++;
    }
  } else {
    ans2[block][poss % sq] += val;
    poss++;
    while (poss % sq != 0) {
      ans2[block][poss % sq] += val;
      poss++;
    }
  }
  block;
  while (block * sq <= n) {
    ans1[block] += val;
    block++;
  }
}
inline long long query(int l, int r) {
  int block = r / sq;
  long long res1 = 0;
  if (block >= 1) {
    res1 = ans1[block - 1];
  }
  res1 += ans2[block][r % sq];
  if (l) {
    long long res2 = 0;
    block = (l - 1) / sq;
    if (block >= 1) {
      res2 = ans1[block - 1];
    }
    if (l >= 1 && block >= 0) res2 += ans2[block][(l - 1) % sq];
    res1 -= res2;
  }
  return res1;
}
long long fans[100009];
void dfs1(int pos, int prev) {
  for (int i = 0; i < tree.out[pos].size(); i++) {
    update(tree.out[pos][i], 1);
  }
  for (int i = 0; i < tree.goin[pos].size(); i++) {
    for (int j = 0; j < que[tree.goin[pos][i]].size(); j++) {
      pair<pair<int, int>, int> x = que[tree.goin[pos][i]][j];
      fans[x.second] += query(x.first.first, x.first.second);
    }
  }
  for (int i = 0; i < gr[pos].size(); i++) {
    if (gr[pos][i] != prev) {
      dfs1(gr[pos][i], pos);
    }
  }
  for (int i = 0; i < tree.out[pos].size(); i++) {
    update(tree.out[pos][i], -1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> pattern[i];
  }
  for (int i = 0; i < n; i++) {
    tree.add_string(pattern[i], i);
  }
  tree.build_automaton();
  for (int i = 0; i < q; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    l--;
    r--;
    k--;
    que[k].push_back({{l, r}, i});
  }
  for (int i = 0; i < n; i++) {
    int p = pattern[i].size();
    if (p >= sq) {
      dfs(0, -1, i);
      for (int j = 1; j < n; j++) {
        ans[j] += ans[j - 1];
      }
      for (int j = 0; j < que[i].size(); j++) {
        pair<pair<int, int>, int> x = que[i][j];
        fans[x.second] = ans[x.first.second] -
                         (x.first.first > 0 ? ans[x.first.first - 1] : 0);
      }
      memset(subsize, 0, sizeof(subsize));
      memset(ans, 0, sizeof(ans));
    }
  }
  dfs1(0, -1);
  for (int i = 0; i < q; i++) {
    cout << fans[i] << "\n";
  }
}
