#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long llread() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
namespace SAM {
struct Node {
  int tranc[26], len, fa, deep;
} a[1000010];
int Size[1000010][11], tot, tail;
int c[1000010], od[1000010];
int ls[11], rs[11];
inline void init() {
  tail = tot = 1;
  memset(ls, 0, sizeof(ls));
  memset(rs, 0x3f, sizeof(rs));
}
inline void insert(int op, int ch) {
  int nq, np = ++tot, p = tail, q;
  if (a[p].tranc[ch]) {
    q = a[p].tranc[ch];
    if (a[q].len == a[p].len + 1)
      tail = q;
    else {
      a[nq = ++tot] = a[q];
      a[q].fa = nq;
      a[nq].len = a[p].len + 1;
      for (; a[p].tranc[ch] == q; p = a[p].fa) a[p].tranc[ch] = nq;
      tail = nq;
    }
  } else {
    np = ++tot;
    a[np].len = a[p].len + 1;
    for (; p && !a[p].tranc[ch]; p = a[p].fa) a[p].tranc[ch] = np;
    if (!p)
      a[np].fa = 1;
    else {
      q = a[p].tranc[ch];
      if (a[q].len == a[p].len + 1)
        a[np].fa = q;
      else {
        a[nq = ++tot] = a[q];
        a[q].fa = a[np].fa = nq;
        a[nq].len = a[p].len + 1;
        for (; a[p].tranc[ch] == q; p = a[p].fa) a[p].tranc[ch] = nq;
      }
    }
    tail = np;
  }
  Size[tail][op]++;
}
inline void solve(int len) {
  for (int i = (1); i <= (tot); i++) c[a[i].len]++;
  for (int i = (1); i <= (len); i++) c[i] += c[i - 1];
  for (int i = (tot); i >= (1); i--) od[c[a[i].len]--] = i;
  for (int i = (tot); i >= (1); i--) {
    int x = od[i];
    for (int j = (0); j <= (10); j++) {
      Size[a[x].fa][j] += Size[x][j];
    }
  }
}
}  // namespace SAM
using namespace SAM;
char str[50010];
inline bool check(int x, int n) {
  for (int i = (0); i <= (n); i++) {
    if (Size[x][i] < ls[i] || Size[x][i] > rs[i]) return false;
  }
  return true;
}
int main() {
  init();
  scanf("%s", str);
  ls[0] = 1, rs[0] = 2147483647;
  int len = strlen(str);
  int cnt = 0;
  for (int i = (0); i < (len); i++) insert(0, str[i] - 'a'), cnt++;
  int n = read();
  for (int i = (1); i <= (n); i++) {
    scanf("%s", str);
    ls[i] = read(), rs[i] = read();
    tail = 1;
    len = strlen(str);
    for (int j = (0); j < (len); j++) insert(i, str[j] - 'a'), cnt++;
  }
  solve(cnt);
  int ans = 0;
  for (int i = (2); i <= (tot); i++) {
    if (check(i, n)) ans += a[i].len - a[a[i].fa].len;
  }
  printf("%d\n", ans);
  return 0;
}
