Problem: What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercase English letters. What is double strange that a phone number can be associated with several bears!

In that country there is a rock band called CF consisting of n bears (including Mike) numbered from 1 to n. 

<image>

Phone number of i-th member of CF is si. May 17th is a holiday named Phone Calls day. In the last Phone Calls day, everyone called all the numbers that are substrings of his/her number (one may call some number several times). In particular, everyone called himself (that was really strange country).

Denote as call(i, j) the number of times that i-th member of CF called the j-th member of CF. 

The geek Mike has q questions that he wants to ask you. In each question he gives you numbers l, r and k and you should tell him the number 

<image>

Input

The first line of input contains integers n and q (1 ≤ n ≤ 2 × 105 and 1 ≤ q ≤ 5 × 105).

The next n lines contain the phone numbers, i-th line contains a string si consisting of lowercase English letters (<image>).

The next q lines contain the information about the questions, each of them contains integers l, r and k (1 ≤ l ≤ r ≤ n and 1 ≤ k ≤ n).

Output

Print the answer for each question in a separate line.

Examples

Input

5 5
a
ab
abab
ababab
b
1 5 1
3 5 1
1 5 2
1 5 3
1 4 5


Output

7
5
6
3
6

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T &a, S b) {
  a += b;
  if (a >= mod) a -= mod;
}
template <class T, class S>
inline void sub(T &a, S b) {
  a -= b;
  if (a < 0) a += mod;
}
template <class T, class S>
inline bool chkmax(T &a, S b) {
  return a < b ? a = b, true : false;
}
template <class T, class S>
inline bool chkmin(T &a, S b) {
  return a > b ? a = b, true : false;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int r[N], sa[N], _t[N], _t2[N], c[N], rk[N], lcp[N], san;
int maxc = 'z' + 1;
void buildSa(int *r, int n, int m) {
  int i, j = 0, k = 0, *x = _t, *y = _t2;
  for (i = 0; i < m; i++) c[i] = 0;
  for (i = 0; i < n; i++) c[x[i] = r[i]]++;
  for (i = 1; i < m; i++) c[i] += c[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;
  for (int k = 1; k <= n; k <<= 1) {
    int p = 0;
    for (i = n - k; i < n; i++) y[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= k) y[p++] = sa[i] - k;
    for (i = 0; i < m; i++) c[i] = 0;
    for (i = 0; i < n; i++) c[x[y[i]]]++;
    for (i = 1; i < m; i++) c[i] += c[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];
    swap(x, y);
    p = 1;
    x[sa[0]] = 0;
    for (int i = 1; i < n; i++) {
      if (y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k])
        x[sa[i]] = p - 1;
      else
        x[sa[i]] = p++;
    }
    if (p >= n) break;
    m = p;
  }
  for (i = 1; i < n; i++) rk[sa[i]] = i;
  for (i = 0; i < n - 1; i++) {
    if (k) k--;
    j = sa[rk[i] - 1];
    while (r[i + k] == r[j + k]) k++;
    lcp[rk[i]] = k;
  }
}
int Log[N];
struct ST {
  int dp[N][20];
  int ty;
  void build(int n, int b[], int _ty) {
    ty = _ty;
    for (int i = -(Log[0] = -1); i < N; i++)
      Log[i] = Log[i - 1] + ((i & (i - 1)) == 0);
    for (int i = 1; i <= n; i++) dp[i][0] = ty * b[i];
    for (int j = 1; j <= Log[n]; j++)
      for (int i = 1; i + (1 << j) - 1 <= n; i++)
        dp[i][j] = max(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
  }
  inline int query(int x, int y) {
    if (x > y) return 0;
    int k = Log[y - x + 1];
    return ty * max(dp[x][k], dp[y - (1 << k) + 1][k]);
  }
} rmq;
struct Bit {
  int a[N];
  void modify(int x, int v) {
    for (int i = x; i < N; i += i & -i) {
      a[i] += v;
    }
  }
  int sum(int x) {
    int ans = 0;
    for (int i = x; i; i -= i & -i) {
      ans += a[i];
    }
    return ans;
  }
  int query(int L, int R) {
    if (L > R) return 0;
    return sum(R) - sum(L - 1);
  }
} bit;
struct Qus {
  int vl, vr, id;
};
int n, q, belong[N], len[N], sid[N];
int ans[N];
char s[N];
vector<Qus> Q[N];
void printSuf(int x) {
  for (int i = sa[x]; i < san; i++) putchar((char)r[i]);
  for (int i = 0; i < (sa[x] + 5); i++) putchar(' ');
  printf("i: %3d  sa: %3d  lcp: %3d  belong: %3d\n", x, sa[x], lcp[x],
         belong[sa[x]]);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    if (i > 1) r[san++] = maxc++;
    scanf("%s", s);
    len[i] = strlen(s);
    sid[i] = san;
    for (int j = 0; s[j]; j++) {
      r[san] = s[j];
      belong[san++] = i;
    }
  }
  r[san] = 0;
  buildSa(r, san + 1, maxc);
  rmq.build(san, lcp, -1);
  for (int i = 1; i <= q; i++) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    int L = rk[sid[k]], R = rk[sid[k]], low, high, mid;
    low = 1, high = rk[sid[k]] - 1;
    while (low <= high) {
      mid = low + high >> 1;
      if (rmq.query(mid + 1, rk[sid[k]]) >= len[k])
        L = mid, high = mid - 1;
      else
        low = mid + 1;
    }
    low = rk[sid[k]] + 1, high = san;
    while (low <= high) {
      mid = low + high >> 1;
      if (rmq.query(rk[sid[k]] + 1, mid) >= len[k]) {
        R = mid, low = mid + 1;
      } else
        high = mid - 1;
    }
    Q[L - 1].push_back(Qus{l, r, -i});
    Q[R].push_back(Qus{l, r, i});
  }
  for (int i = 1; i <= san; i++) {
    if (belong[sa[i]]) {
      bit.modify(belong[sa[i]], 1);
    }
    for (auto &q : Q[i]) {
      if (q.id > 0)
        ans[q.id] += bit.query(q.vl, q.vr);
      else
        ans[-q.id] -= bit.query(q.vl, q.vr);
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}