#include <bits/stdc++.h>
using namespace std;
int l[15], r[15], br[15];
char s[255], p[15][255];
string rs[50333], st[11][50333];
int main() {
  int n, m, i, j, k, t, bb, bru, brr, res;
  string *fl, *fr;
  string ps;
  scanf("%s", &s);
  n = strlen(s);
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%s%d%d", &p[i], &l[i], &r[i]);
    t = strlen(p[i]);
    ps = "";
    br[i] = 0;
    for (j = 0; j < t; j++) {
      ps = "";
      for (k = j; k < t; k++) {
        ps += p[i][k];
        st[i][br[i]++] = ps;
      }
    }
    sort(st[i], st[i] + br[i]);
  }
  res = 0;
  bru = 0;
  for (i = 0; i < n; i++) {
    ps = "";
    for (j = i; j < n; j++) {
      ps += s[j];
      bb = 1;
      for (k = 0; k < m; k++) {
        fl = lower_bound(st[k], st[k] + br[k], ps);
        fr = upper_bound(st[k], st[k] + br[k], ps);
        brr = (fr - fl);
        if (brr < l[k] || brr > r[k]) {
          bb = 0;
        }
      }
      if (bb) {
        rs[bru++] = ps;
      }
    }
  }
  sort(rs, rs + bru);
  i = 0;
  while (i < bru) {
    res++;
    while (i + 1 < bru && rs[i] == rs[i + 1]) i++;
    i++;
  }
  printf("%d\n", res);
  return 0;
}
