#include <bits/stdc++.h>
using namespace std;
long long inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T>
long long chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
long long chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T mmin(T a, T b) {
  return a < b ? a : b;
}
template <class T>
T mmax(T a, T b) {
  return a > b ? a : b;
}
template <class T>
T aabs(T a) {
  return a < 0 ? -a : a;
}
template <class T>
long long dcmp(T a, T b) {
  return a > b;
}
template <long long *a>
long long cmp_a(long long first, long long second) {
  return a[first] < a[second];
}
struct __INIT__ {
  __INIT__() { memset(&inf, 0x3f, sizeof(inf)); }
} __INIT___;
namespace io {
const long long SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
long long f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char first) {
  *oS++ = first;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &first) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (first = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    first = first * 10 + (c & 15);
  first *= f;
  return 1;
}
inline bool read(char &first) {
  while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)) == ' ' ||
         first == '\n' || first == '\r')
    ;
  return first != EOF;
}
inline bool read(char *first) {
  while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                                (iS == iT ? EOF : *iS++))
                             : *iS++)) == '\n' ||
         *first == ' ' || *first == '\r')
    ;
  if (*first == EOF) return 0;
  while (!(*first == '\n' || *first == ' ' || *first == '\r'))
    *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                           : *iS++);
  *first = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &first, B &...second) {
  return read(first) && read(second...);
}
template <typename A>
inline bool write(A first) {
  if (!first) putc('0');
  if (first < 0) putc('-'), first = -first;
  while (first) qu[++qr] = first % 10 + '0', first /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char first) {
  putc(first);
  return 0;
}
inline bool write(const char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
inline bool write(char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A first, B... second) {
  return write(first) || write(second...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
char strs[1000005];
char *s[100005];
long long to[100005][26], t = 1, fail[100005];
long long c[100005];
long long ed[100005];
long long q[100005], *l, *r;
long long cnt[201][100005];
long long is[100005];
long long ans[100005];
vector<pair<long long, long long> > ask[100005];
const long long S = 500;
long long dfn[100005], low[100005], su[100005];
long long cl;
void add(long long first, long long second) {
  for (; first <= cl; first += first & -first) su[first] += second;
}
long long sum(long long first) {
  long long second = 0;
  for (; first; first ^= first & -first) second += su[first];
  return second;
}
vector<long long> son[100005];
void dfs(long long first) {
  dfn[first] = ++cl;
  for (auto i : son[first]) dfs(i);
  low[first] = cl;
}
signed main() {
  long long n, m;
  read(n, m);
  s[1] = strs;
  for (long long i = 1; i <= n; ++i) {
    read(s[i]);
    s[i + 1] = s[i] + strlen(s[i]);
    long long at = 1;
    for (char *j = s[i]; j < s[i + 1]; ++j) {
      if (!to[at][*j - 'a']) to[at][*j - 'a'] = ++t;
      at = to[at][*j - 'a'];
    }
    ed[i] = at;
  }
  *(l = r = q) = 1;
  fail[1] = 1;
  while (l <= r) {
    for (long long i = 0; i < 26; ++i)
      if (to[*l][i]) {
        *(++r) = to[*l][i];
        if (*l == 1) {
          fail[*r] = 1;
        } else {
          long long at = fail[*l];
          while (at != 1 && !to[at][i]) at = fail[at];
          if (to[at][i])
            fail[*r] = to[at][i];
          else
            fail[*r] = 1;
        }
        son[fail[*r]].push_back(*r);
      }
    ++l;
  }
  l = q;
  while (l <= r) {
    for (long long i = 0; i < 26; ++i)
      if (!to[*l][i]) {
        if (*l == 1)
          to[*l][i] = 1;
        else
          to[*l][i] = to[fail[*l]][i];
      }
    ++l;
  }
  long long ct = 0;
  for (long long i = 1; i <= n; ++i) {
    if (s[i + 1] - s[i] > S) {
      is[i] = ++ct;
      long long at = 1;
      for (char *j = s[i]; j < s[i + 1]; ++j) {
        at = to[at][*j - 'a'];
        ++c[at];
      }
      for (long long *j = r;; --j) {
        c[fail[*j]] += c[*j];
        if (j == q) break;
      }
      for (long long j = 1; j <= n; ++j) cnt[ct][j] = cnt[ct][j - 1] + c[ed[j]];
      for (long long j = 1; j <= t; ++j) c[j] = 0;
    }
  }
  for (long long i = 1; i <= m; ++i) {
    long long l, r, k;
    read(l, r, k);
    if (s[k + 1] - s[k] > S) {
      ans[i] = cnt[is[k]][r] - cnt[is[k]][l - 1];
    } else {
      ask[r].push_back(make_pair(k, i));
      ask[l - 1].push_back(make_pair(k, -i));
    }
  }
  dfs(1);
  for (long long i = 1; i <= n; ++i) {
    add(dfn[ed[i]], 1);
    add(low[ed[i]] + 1, -1);
    for (auto j : ask[i]) {
      long long aid = j.second, tp = 1;
      if (aid < 0) {
        aid = -aid;
        tp = -1;
      }
      long long at = 1;
      for (char *l = s[j.first]; l < s[j.first + 1]; ++l) {
        at = to[at][*l - 'a'];
        ans[aid] += tp * sum(dfn[at]);
      }
    }
  }
  for (long long i = 1; i <= m; ++i) write(ans[i], '\n');
  return 0;
}
