#include <bits/stdc++.h>
using namespace std;
const long long p = 131;
vector<pair<long long, int> > f(const string& s) {
  vector<long long> h;
  for (int i = 0; i < s.size(); ++i) {
    long long cur = 0;
    for (int j = i; j < s.size(); ++j) {
      cur = cur * p + s[j];
      h.push_back(cur);
    }
  }
  sort(h.begin(), h.end());
  vector<pair<long long, int> > res(1, pair<long long, int>(h[0], 1));
  for (int i = 1; i < h.size(); ++i) {
    if (h[i] == h[i - 1])
      ++res.back().second;
    else
      res.push_back(pair<long long, int>(h[i], 1));
  }
  return res;
}
int main() {
  vector<long long> pw(2005, 1);
  for (int i = 1; i < pw.size(); ++i) pw[i] = pw[i - 1] * p;
  string s;
  int n;
  cin >> s >> n;
  vector<pair<long long, int> > all = f(s);
  vector<int> ok(all.size(), 1);
  for (int ii = 0; ii < n; ++ii) {
    string v;
    int l, r;
    cin >> v >> l >> r;
    vector<pair<long long, int> > cur = f(v);
    for (int i = 0; i < all.size(); ++i)
      if (ok[i]) {
        int it = lower_bound(cur.begin(), cur.end(),
                             pair<long long, int>(all[i].first, 0)) -
                 cur.begin();
        if (it < cur.size() && all[i].first == cur[it].first) {
          if (cur[it].second < l || cur[it].second > r) ok[i] = 0;
        } else {
          if (l > 0) ok[i] = 0;
        }
      }
  }
  int cnt = 0;
  for (int i = 0; i < ok.size(); ++i) cnt += ok[i];
  cout << cnt << endl;
  return 0;
}
