#include <bits/stdc++.h>
using namespace std;
template <class T>
T inline Abs(const T& x) {
  return x < 0 ? -x : x;
}
template <class T>
T inline Sqr(const T& x) {
  return x * x;
}
long long p = 1543;
long long P[100000];
int main(int argc, char* argv[]) {
  P[0] = 1;
  for (int i = 1; i < 100000; ++i) {
    P[i] = P[i - 1] * p;
  }
  string s;
  int n;
  cin >> s >> n;
  vector<string> t(n);
  vector<int> l(n), r(n);
  for (int i = 0; i < n; ++i) {
    cin >> t[i] >> l[i] >> r[i];
  }
  long long ans = 0;
  for (int len = 1; len <= s.length(); ++len) {
    long long h = 0;
    for (int i = 0; i < len; ++i) {
      h = h * p + s[s.length() - 1 - i];
    }
    unordered_map<long long, vector<int> > mp;
    for (int i = s.length() - len; i >= 0; --i) {
      mp[h] = vector<int>(n, 0);
      if (i > 0) {
        h -= s[i + len - 1] * P[len - 1];
        h *= p;
        h += s[i - 1];
      }
    }
    for (int pr = 0; pr < n; ++pr) {
      if (len > t[pr].length()) {
        continue;
      }
      long long h = 0;
      for (int i = 0; i < len; ++i) {
        h = h * p + t[pr][t[pr].length() - 1 - i];
      }
      for (int i = t[pr].length() - len; i >= 0; --i) {
        if (mp.count(h)) {
          ++mp[h][pr];
        }
        if (i > 0) {
          h -= t[pr][i + len - 1] * P[len - 1];
          h *= p;
          h += t[pr][i - 1];
        }
      }
    }
    for (auto it = mp.begin(); it != mp.end(); ++it) {
      bool good = true;
      for (int i = 0; i < n; ++i) {
        if (it->second[i] < l[i] || it->second[i] > r[i]) {
          good = false;
          break;
        }
      }
      if (good) {
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
