#include <bits/stdc++.h>
using namespace std;
char s[2010], ms[11][2010];
int num[11][2010], n, L[12], R[12];
set<long long> cot;
int judge(char ch) {
  int i, j, t, flag = 1;
  for (i = 1; i <= n; i++) {
    t = 0;
    for (j = 1; j <= num[i][0]; j++) {
      if (ch == ms[i][num[i][j]]) num[i][++t] = num[i][j] + 1;
    }
    num[i][0] = t;
    if (t >= L[i] && t <= R[i])
      ;
    else
      flag = 0;
  }
  return flag;
}
int main() {
  int i, j, k, m, t;
  long long sum;
  while (scanf("%s", s) != EOF) {
    m = strlen(s);
    cot.clear();
    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%s%d%d", ms[i], &L[i], &R[i]);
    for (i = 0; i < m; i++) {
      for (k = 1; k <= n; k++) {
        num[k][0] = 0;
        for (j = 0; ms[k][j]; j++) num[k][++num[k][0]] = j;
      }
      sum = 0;
      for (j = i; j < m; j++) {
        sum = sum * 37 + s[j] - 'a' + 1;
        if (judge(s[j])) {
          cot.insert(sum);
        }
      }
    }
    printf("%d\n", cot.size());
  }
  return 0;
}
