#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int main(int argc, char *argv[]) {
  string s, p;
  int n, l, r;
  cin >> s >> n;
  pair<string, pair<int, int> > a[n];
  for (int i = (0), _b = (n); i < (_b); ++i)
    cin >> a[i].first >> a[i].second.first >> a[i].second.second;
  int sz = s.length();
  int ans = 0;
  set<string> used;
  for (int i = (0), _b = (sz); i < (_b); ++i) {
    string t = "";
    for (int j = (i), _b = (sz); j < (_b); ++j) {
      t += s[j];
      if (((used).find(t) != (used).end())) continue;
      int good = 0;
      for (int k = (0), _b = (n); k < (_b); ++k) {
        int cnt = 0;
        size_t found = a[k].first.find(t);
        while (found != string::npos) {
          ++cnt;
          found = a[k].first.find(t, found + 1);
        }
        if (cnt >= a[k].second.first && cnt <= a[k].second.second)
          ++good;
        else
          break;
      }
      if (good == n) {
        used.insert(t);
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
