#include <bits/stdc++.h>
using namespace std;
struct Rule {
  string s;
  int l, r;
  bool accepts(string query) {
    int cnt = 0;
    for (int i = 0; i <= (int)s.size() - (int)query.size(); ++i)
      if (s.substr(i, query.size()) == query) ++cnt;
    return l <= cnt && cnt <= r;
  }
};
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<Rule> rules(n);
  for (int i = 0; i < n; ++i) cin >> rules[i].s >> rules[i].l >> rules[i].r;
  set<string> ans;
  for (int i = 0; i < s.size(); ++i)
    for (int j = 1; j <= s.size() - i; ++j) {
      int cnt = 0;
      for (Rule rule : rules) cnt += rule.accepts(s.substr(i, j));
      if (cnt == n) ans.insert(s.substr(i, j));
    }
  cout << ans.size() << '\n';
}
