#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast")
#pragma GCC target("avx")
using namespace std;
template <class t>
inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 1e6 + 5;
int noden = 1, ch[N][30], len[N], f[N], n, L[N], R[N], sz[N][15], du[N];
queue<int> q;
long long ans;
char s[N];
int insert(int k, int last) {
  if (ch[last][k] && len[last] + 1 == len[ch[last][k]]) return ch[last][k];
  int x = ++noden, p = last, flag = 0, q, copy;
  len[x] = len[last] + 1;
  while (p && !ch[p][k]) ch[p][k] = x, p = f[p];
  if (!p)
    f[x] = 1;
  else {
    q = ch[p][k];
    if (len[p] + 1 == len[q])
      f[x] = q;
    else {
      if (len[p] + 1 == len[x]) flag = 1;
      copy = ++noden;
      len[copy] = len[p] + 1;
      for (int i = 0; i < 26; i++) ch[copy][i] = ch[q][i];
      f[copy] = f[q];
      f[q] = f[x] = copy;
      for (; ch[p][k] == q; p = f[p]) ch[p][k] = copy;
    }
  }
  return flag ? copy : x;
}
bool check(int x) {
  for (int i = 1; i <= n; i++)
    if (sz[x][i] < L[i] || sz[x][i] > R[i]) return 0;
  return 1;
}
signed main() {
  scanf("%s", s);
  for (int i = 0, last = 1; s[i]; i++)
    last = insert(s[i] - 'a', last), sz[last][0] = 1;
  read(n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    for (int j = 0, last = 1; s[j]; j++)
      last = insert(s[j] - 'a', last), sz[last][i] = 1;
    read(L[i]);
    read(R[i]);
  }
  for (int i = 2; i <= noden; i++) du[f[i]]++;
  for (int i = 1; i <= noden; i++)
    if (!du[i]) q.push(i);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i <= n; i++) sz[f[x]][i] += sz[x][i];
    if (!--du[f[x]]) q.push(f[x]);
  }
  for (int i = 2; i <= noden; i++)
    if (sz[i][0] && check(i)) ans += len[i] - len[f[i]];
  write(ans);
}
