#include <bits/stdc++.h>
using namespace std;
char p[15][2100];
int l[15];
int r[15];
char s[2100];
int n;
vector<int> pfunc(string s, string t) {
  string res = s + '$' + t;
  vector<int> p(res.size());
  for (int i = 1; i < (int)res.size(); i++) {
    int j = p[i - 1];
    while (j && res[j] != res[i]) {
      j = p[j - 1];
    }
    if (res[j] == res[i]) j++;
    p[i] = j;
  }
  vector<int> cnt(s.size() + 1);
  for (int i = (int)s.size() + 1; i < (int)res.size(); i++) {
    assert(p[i] <= (int)s.size());
    cnt[p[i]]++;
  }
  for (int i = (int)s.size(); i > 0; i--) cnt[p[i - 1]] += cnt[i];
  return cnt;
}
vector<int> cnts[15];
bool check(int len) {
  for (int i = 0; i < n; i++)
    if (!(l[i] <= cnts[i][len] && cnts[i][len] <= r[i])) return 0;
  return 1;
}
int lcp[2100];
int main() {
  scanf("%s", s);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s %d %d", p[i], &l[i], &r[i]);
  int ans = 0;
  int slen = strlen(s);
  for (int i = slen - 1; i >= 0; i--) {
    for (int j = 0; j < n; j++) cnts[j] = pfunc(s + i, p[j]);
    for (int j = 0; j < slen; j++) lcp[j] = (s[i] == s[j]) ? lcp[j + 1] + 1 : 0;
    for (int len = (i ? *max_element(lcp, lcp + i) : 0) + 1; s[i + len - 1];
         len++) {
      ans += check(len);
    }
  }
  printf("%d\n", ans);
  ;
  return 0;
}
