#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
typedef unsigned long long ull;
struct StrComparator {
static const ull P = 239017;
static vector <ull> deg;
int n;
const char *s;
ull *h;
StrComparator( const string &s ) : n(sz(s)), s(s.c_str()) {
h = new ull[n + 1];
h[0] = 0;
forn(i, n)
h[i + 1] = h[i] * P + s[i];
deg.reserve(n);
while (sz(deg) <= n)
deg.pb(*deg.rbegin() * P);
}
ull substr( int i, int len ) const { return h[i + len] - h[i] * deg[len]; }
};
vector <ull> StrComparator::deg(1, 1);
typedef vector<int> vi;
const int N = 2e5;
const int SZ = 3e5 + 7;
const int K = 500;
int n, q, l[N], r[N], ans[N];
string s[N], p[N];
StrComparator *h[N];
vi ind[N + 1];
unordered_map<ull, vi> table;
int main() {
#define NAME "str-qry"
assert(freopen(NAME ".in", "r", stdin));
assert(freopen(NAME ".out", "w", stdout));
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> q;
forn(i, n) {
cin >> s[i];
h[i] = new StrComparator(s[i]);
}
forn(i, q) {
cin >> l[i] >> r[i] >> p[i], l[i]--, r[i]--;
ind[p[i].size()].pb(i);
}
forn(L, N + 1) // process length L
if (ind[L].size()) {
table.clear();
forn(i, n)
for (int j = 0; j + L <= sz(s[i]); j++) {
vi &v = table[h[i]->substr(j, L)];
if (!sz(v) || *v.rbegin() != i)
v.pb(i);
}
for (int i : ind[L]) {
vi &v = table[StrComparator(p[i]).substr(0, sz(p[i]))];
ans[i] = upper_bound(all(v), r[i]) - lower_bound(all(v), l[i]);
}
}
forn(i, q)
cout << ans[i] << "\n";
}