#include <bits/stdc++.h>
using namespace std;
void preKmp(char *src, int m, int *rule) {
  int i = 0, j = -1;
  rule[0] = j;
  while (i < m) {
    while (j != -1 && src[j] != src[i]) j = rule[j];
    i++, j++;
    if (j >= m)
      rule[i] = rule[j - 1];
    else
      rule[i] = j;
  }
}
int recount = 0;
void kmp(char *src, int m, char *dest, int n) {
  int rule[10005];
  preKmp(src, m, rule);
  int i = 0, j = 0;
  while (i < n) {
    while (j != -1 && src[j] != dest[i]) {
      j = rule[j];
    }
    i++, j++;
    if (j == m) {
      recount++;
      j = rule[j];
    }
  }
}
char Reg[10005], ori[1000005];
char os[100][300], a[500], temp[500];
int l[100], r[100], n, len, le[100];
int main() {
  set<string> now;
  set<string>::iterator iter;
  bool flag;
  int ans = 0, i, j, k;
  while (scanf("%s", a) != EOF) {
    now.clear();
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
      scanf("%s%d%d", os[i], &l[i], &r[i]);
      le[i] = strlen(os[i]);
    }
    len = strlen(a);
    ans = 0;
    for (i = 0; i < len; i++)
      for (j = i; j < len; j++) {
        flag = true;
        for (k = 1; k <= n; k++) {
          recount = 0;
          kmp(a + i, j - i + 1, os[k], le[k]);
          if (recount < l[k] || recount > r[k]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          for (k = i; k <= j; k++) temp[k - i] = a[k];
          temp[k - i] = '\0';
          string wc = temp;
          iter = now.find(wc);
          if (iter == now.end()) {
            now.insert(wc);
            ans++;
          }
        }
      }
    printf("%d\n", ans);
  }
}
