#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:67108864")
template <class T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T Abs(T a) {
  return a > T(0) ? a : -a;
}
template <class T>
inline T Sqr(T a) {
  return a * a;
}
template <class T>
inline T gcd(T a, T b) {
  while (b > 0) {
    a %= b;
    T c = a;
    a = b;
    b = c;
  };
  return a;
}
using namespace std;
string str, s[15];
int i, j, n, l[15], r[15], len, rule;
set<string> ans;
int main() {
  cin >> str;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> s[i] >> l[i] >> r[i];
  }
  len = str.length();
  for (i = len; i < 3 * len; ++i) str.push_back('#');
  for (i = 0; i < len; ++i) {
    for (j = 1; i + j <= len; ++j) {
      string ss = str.substr(i, j);
      int dd = 0;
      for (rule = 0; rule < n; ++rule) {
        int cnt = 0, d = s[rule].length();
        for (int it = 0; it + ss.length() <= d; ++it)
          if (s[rule].substr(it, ss.length()) == ss) ++cnt;
        if (cnt >= l[rule] && cnt <= r[rule]) dd++;
      }
      if (dd == n) ans.insert(ss);
    }
  }
  printf("%d\n", ans.size());
  return 0;
}
