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;
template <class T>
void setmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
const int MAXLEN = 400010;
const int MAXLogN = 22;
namespace SA {
int sa[MAXLEN], rank[MAXLEN], height[MAXLEN], limit[MAXLEN];
int wxa[MAXLEN], wxb[MAXLEN], wxc[MAXLEN];
int str[MAXLEN];
int len;
void cal_sa() {
  int *x = wxa, *y = wxb, *c = wxc, size = MAXLEN - 10;
  for (int i = 0; i <= size; ++i) c[i] = 0;
  for (int i = 1; i <= len; ++i) ++c[x[i] = (int)str[i]];
  for (int i = 1; i <= size; ++i) c[i] += c[i - 1];
  for (int i = len; i >= 1; --i) sa[c[x[i]]--] = i;
  for (int w = 1; w < len; w *= 2, size = len) {
    int p = 0;
    for (int i = len - w + 1; i <= len; ++i) y[++p] = i;
    for (int i = 1; i <= len; ++i)
      if (sa[i] > w) y[++p] = sa[i] - w;
    for (int i = 0; i <= size; ++i) c[i] = 0;
    for (int i = 1; i <= len; ++i) ++c[x[i]];
    for (int i = 1; i <= size; ++i) c[i] += c[i - 1];
    for (int i = len; i >= 1; --i) sa[c[x[y[i]]]--] = y[i];
    std::swap(x, y);
    x[sa[1]] = 1;
    for (int i = 2; i <= len; ++i) {
      int j1 = sa[i - 1], j2 = sa[i];
      int c1 = y[j1], c2 = y[j2];
      if (c1 == c2) {
        c1 = (j1 + w <= len ? y[j1 + w] : 0);
        c2 = (j2 + w <= len ? y[j2 + w] : 0);
      }
      x[j2] = x[j1] + (c1 < c2);
    }
  }
}
void cal_height() {
  for (int i = 1; i <= len; ++i) rank[sa[i]] = i;
  for (int i = 1, h = 0; i <= len; ++i) {
    if (h > 0) --h;
    int j = sa[rank[i] - 1];
    while (i + h <= len && j + h <= len && str[i + h] == str[j + h]) ++h;
    height[rank[i]] = h;
  }
}
int lcp_st[MAXLogN][MAXLEN];
int lcp_k[MAXLEN], lcp_w[MAXLEN];
void cal_lcp() {
  for (int i = 2; i <= len; ++i) lcp_st[0][i] = height[i];
  for (int k = 1, w = 1; 2 + w <= len; ++k, w *= 2)
    for (int i = 2; i + w <= len; ++i)
      lcp_st[k][i] = min(lcp_st[k - 1][i], lcp_st[k - 1][i + w]);
  for (int i = 1, k = 0, w = 1; i <= len; ++i) {
    while (w * 2 <= i) w *= 2, ++k;
    lcp_k[i] = k, lcp_w[i] = w;
  }
}
int lcp(int i, int j) {
  if (i == j) return limit[i];
  i = rank[i], j = rank[j];
  if (i > j) swap(i, j);
  ++i;
  int k = lcp_k[j - i + 1], w = lcp_w[j - i + 1];
  return min(lcp_st[k][i], lcp_st[k][j - w + 1]);
}
pair<int, int> extend(int i, int lbound) {
  int j = rank[i];
  i = j;
  for (int k = int((MAXLogN)-1); k >= int(0); --k)
    if (i - (1 << k) >= 1 && lcp_st[k][i - (1 << k) + 1] >= lbound)
      i -= (1 << k);
  for (int k = int((MAXLogN)-1); k >= int(0); --k)
    if (j + (1 << k) <= len && lcp_st[k][j + 1] >= lbound) j += (1 << k);
  return make_pair(i, j);
}
};  // namespace SA
const int MAXN = 200010;
int cnt = 0;
struct Arr {
  int a[MAXLEN], n;
  struct Node {
    int size, l, r;
  } tr[MAXLEN * (MAXLogN + 2)];
  int roots[MAXLEN], num;
  int ins(int x, int val, int bit) {
    tr[++num] = tr[x];
    x = num;
    ++tr[x].size;
    if (bit >= 0) {
      if (val & (1 << bit))
        tr[x].r = ins(tr[x].r, val, bit - 1);
      else
        tr[x].l = ins(tr[x].l, val, bit - 1);
    }
    return x;
  }
  void cal() {
    memset(&tr[0], 0, sizeof(tr[0]));
    roots[0] = 0;
    num = 0;
    for (int i = int(1); i <= int(n); ++i)
      roots[i] = ins(roots[i - 1], a[i], MAXLogN - 1);
  }
  int query(int i, int ri) {
    int ans = 0, x = roots[i];
    for (int k = int((MAXLogN)-1); k >= int(0); --k) {
      if (ri & (1 << k)) {
        ans += tr[tr[x].l].size;
        x = tr[x].r;
      } else
        x = tr[x].l;
    }
    ans += tr[x].size;
    return ans;
  }
  int query(int l, int r, int le, int ri) {
    int ans1 = query(r, ri) - query(r, le - 1);
    int ans2 = query(l - 1, ri) - query(l - 1, le - 1);
    return ans1 - ans2;
  }
} arr;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  static string s[MAXN];
  static int le[MAXN], ri[MAXN];
  for (int i = int(1); i <= int(n); ++i) {
    static char buf[MAXN];
    scanf("%s", buf);
    s[i] = string(buf);
  }
  int null = 500;
  SA::len = 0;
  for (int i = int(1); i <= int(n); ++i) {
    le[i] = SA::len + 1;
    for (char c : s[i]) SA::str[++SA::len] = (int)c;
    ri[i] = SA::len;
    SA::str[++SA::len] = null++;
  }
  SA::cal_sa();
  SA::cal_height();
  SA::cal_lcp();
  arr.n = SA::len;
  for (int i = int(1); i <= int(arr.n); ++i) arr.a[i] = SA::sa[i];
  arr.cal();
  static pair<int, int> es[MAXN];
  for (int k = int(1); k <= int(n); ++k)
    es[k] = SA::extend(le[k], ri[k] - le[k] + 1);
  while (q--) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    pair<int, int> e = es[k];
    int ans = arr.query(e.first, e.second, le[l], ri[r]);
    printf("%d\n", ans);
  }
  return 0;
}