#include <bits/stdc++.h>
using namespace std;
const int N = 1100010;
int n, tot, cnt, last, ans;
int len[11], L[11], R[11], s[N][11], ch[N][26], pre[N], mx[N], to[N], nt[N],
    head[N], ml[N];
char S[11][50010];
void Insert(int x) {
  int p = last, np = ++cnt, q, nq;
  last = np;
  mx[np] = mx[p] + 1;
  for (; p && !ch[p][x]; p = pre[p]) ch[p][x] = np;
  if (!p)
    pre[np] = 1;
  else {
    q = ch[p][x];
    if (mx[q] == mx[p] + 1)
      pre[np] = q;
    else {
      nq = ++cnt;
      if (mx[q] == mx[p] + 1)
        pre[np] = q;
      else {
        nq = ++cnt;
        pre[nq] = pre[q];
        pre[q] = pre[np] = nq;
        mx[nq] = mx[p] + 1;
        memcpy(ch[nq], ch[q], sizeof(ch[q]));
        for (; p && ch[p][x] == q; p = pre[p]) ch[p][x] = nq;
      }
    }
  }
}
void add(int f, int t) {
  to[++tot] = t;
  nt[tot] = head[f];
  head[f] = tot;
}
void dfs(int x) {
  for (int i = head[x]; i; i = nt[i]) {
    dfs(to[i]);
    for (int j = 0; j <= n; ++j) s[x][j] += s[to[i]][j];
  }
}
int main() {
  scanf("%s%d", S[0], &n);
  len[0] = strlen(S[0]);
  last = cnt = 1;
  for (int i = 1; i <= n; ++i)
    scanf("%s%d%d", S[i], &L[i], &R[i]), len[i] = strlen(S[i]);
  for (int i = 0; i <= n; ++i) {
    last = 1;
    for (int j = 0; j < len[i]; ++j) Insert(S[i][j] - 'a'), ++s[last][i];
  }
  for (int i = 2; i <= cnt; ++i) add(pre[i], i);
  dfs(1);
  for (int i = 2, j; i <= cnt; ++i)
    if (s[i][0]) {
      for (j = 1; j <= n; ++j)
        if (s[i][j] < L[j] || R[j] < s[i][j]) break;
      if (j > n) ans += mx[i] - mx[pre[i]];
    }
  cout << ans;
  return 0;
}
