#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
int n, q, firstApp[N];
string s[N];
vector<int> app[N];
map<string, int> lol;
unordered_map<int, int> cnt[N];
struct Aho {
  struct Node {
    int child[26], fin, par, cha, link[26], id2;
    Node() {
      memset(child, -1, sizeof child);
      memset(link, -1, sizeof link);
      fin = -1;
      par = -1;
      cha = -1;
      id2 = -1;
    }
  } t[N];
  int sz = 0;
  void init() { sz++; }
  void add(string &s, int id) {
    int cur = 0;
    for (int i = 0; i < s.length(); i++) {
      int cha = s[i] - 'a';
      if (t[cur].child[cha] == -1) {
        t[cur].child[cha] = sz;
        t[sz].par = cur;
        t[sz].cha = cha;
        sz++;
      }
      cur = t[cur].child[cha];
    }
    t[cur].fin = id;
  }
  int getLink(int u, int cha) {
    if (t[u].link[cha] != -1) return t[u].link[cha];
    int sufLink = getLink(t[u].par, t[u].cha);
    if (t[sufLink].child[cha] != -1)
      t[u].link[cha] = t[sufLink].child[cha];
    else
      t[u].link[cha] = getLink(sufLink, cha);
    return t[u].link[cha];
  }
  int getID2(int u) {
    if (t[u].id2 != -1) return t[u].id2;
    int tmp = getLink(t[u].par, t[u].cha);
    if (t[tmp].fin == -1)
      t[u].id2 = getID2(tmp);
    else
      t[u].id2 = tmp;
    return t[u].id2;
  }
  void buildLinks() {
    for (int i = 0; i < 26; i++) t[0].link[i] = 0;
    for (int i = 1; i < sz; i++)
      for (int j = 0; j < 26; j++) getLink(i, j);
    t[0].id2 = inf;
    for (int i = 1; i < sz; i++) getID2(i);
  }
  int go(int u, int j) {
    if (t[u].child[j] != -1)
      return t[u].child[j];
    else
      return t[u].link[j];
  }
} aho;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    if (!lol.count(s[i])) lol[s[i]] = i;
    firstApp[i] = lol[s[i]];
    app[firstApp[i]].push_back(i);
  }
  aho.init();
  for (int i = 0; i < n; i++)
    if (firstApp[i] == i) aho.add(s[i], i);
  aho.buildLinks();
  for (int i = 0; i < n; i++) {
    int curNode = 0;
    for (int j = 0; j < s[i].length(); j++) {
      curNode = aho.go(curNode, s[i][j] - 'a');
      int cur2 = curNode;
      while (cur2 != inf) {
        cnt[i][aho.t[cur2].fin]++;
        cur2 = aho.t[cur2].id2;
      }
    }
  }
  while (q--) {
    int l, r, k;
    cin >> l >> r >> k;
    l--, r--, k--;
    long long ans = 0;
    for (auto j : cnt[k]) {
      int cntApp = j.second, pos = j.first;
      ans += 1ll * cntApp *
             (upper_bound(app[pos].begin(), app[pos].end(), r) -
              lower_bound(app[pos].begin(), app[pos].end(), l));
    }
    cout << ans << "\n";
  }
  return 0;
}
