#include <bits/stdc++.h>
using namespace std;
int read() {
  char x = getchar();
  int ans = 0, flag = 1;
  while (!isdigit(x))
    if (x == '-')
      flag = -1, x = getchar();
    else
      x = getchar();
  while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar();
  return ans * flag;
}
int N, n, q, anss[500005], pnt[500005], nxt[500005], head[500005],
    endpos[200005], E;
string x[200005];
struct node {
  int id, a, b, c;
  bool operator<(node x) const { return b < x.b; }
} Q[1000005];
void add_edge(int u, int v) {
  pnt[E] = v;
  nxt[E] = head[u];
  head[u] = E++;
}
struct BIT {
  int tree[200005];
  int lowbit(int x) { return x & -x; }
  void update(int x) {
    while (x <= N) {
      tree[x]++;
      x += lowbit(x);
    }
  }
  int query(int x) {
    int ans = 0;
    while (x) {
      ans += tree[x];
      x -= lowbit(x);
    }
    return ans;
  }
} BIT;
struct AC {
  int tree[200005][26], fail[200005], siz[200005], dfn[200005], tot, cnt;
  void insert(string x, int id) {
    int now = 0;
    for (int i = 0; i < x.length(); i++) {
      if (!tree[now][x[i] - 'a']) tree[now][x[i] - 'a'] = ++tot;
      now = tree[now][x[i] - 'a'];
    }
    endpos[id] = now;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 26; i++) {
      if (tree[0][i]) {
        add_edge(0, tree[0][i]);
        q.push(tree[0][i]);
      }
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (tree[u][i]) {
          q.push(tree[u][i]);
          add_edge(tree[fail[u]][i], tree[u][i]);
          fail[tree[u][i]] = tree[fail[u]][i];
        } else
          tree[u][i] = tree[fail[u]][i];
      }
    }
  }
  void dfs(int u) {
    siz[u] = 1;
    dfn[u] = ++cnt;
    for (int i = head[u]; i != -1; i = nxt[i]) {
      int v = pnt[i];
      dfs(v);
      siz[u] += siz[v];
    }
  }
  void query(string x) {
    int now = 0;
    for (int i = 0; i < x.length(); i++) {
      now = tree[now][x[i] - 'a'];
      BIT.update(dfn[now]);
    }
  }
} AC;
signed main() {
  memset(head, -1, sizeof(head));
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    AC.insert(x[i], i);
  }
  for (int i = 1; i <= q; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    Q[i * 2 - 1] = node{i, c, a - 1, -1};
    Q[i * 2] = node{i, c, b, 1};
  }
  AC.build();
  sort(Q + 1, Q + q * 2 + 1);
  AC.dfs(0);
  N = AC.cnt;
  int pos = 1;
  while (pos <= 2 * q && Q[pos].b == 0) pos++;
  for (int i = 1; i <= n; i++) {
    AC.query(x[i]);
    while (pos <= 2 * q && Q[pos].b == i) {
      int a = Q[pos].a, b = Q[pos].b, id = Q[pos].id, c = Q[pos].c;
      if (a < 1) {
        pos++;
        continue;
      }
      int tmp = BIT.query(AC.dfn[endpos[a]] + AC.siz[endpos[a]] - 1) -
                BIT.query(AC.dfn[endpos[a]] - 1);
      anss[id] += c * tmp;
      pos++;
    }
  }
  for (int i = 1; i <= q; i++) cout << anss[i] << '\n';
  return 0;
}
