#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
template <class T>
T sqr(T a) {
  return a * a;
}
struct con {
  string s;
  int l, r;
};
vector<con> c;
int n;
bool ok(string &s) {
  for (int it = 0; it < n; ++it) {
    string t = s + "#" + c[it].s;
    vector<int> pi(t.length(), 0);
    for (int i = 1; i < t.length(); ++i) {
      int j = pi[i - 1];
      while (j > 0 && t[j] != t[i]) j = pi[j - 1];
      if (t[j] == t[i]) ++j;
      pi[i] = j;
    }
    int q = 0;
    for (int i = s.length(); i < t.length(); ++i) {
      q += pi[i] == s.length();
    }
    if (q < c[it].l || q > c[it].r) return 0;
  }
  return 1;
}
void solve() {
  string s;
  cin >> s;
  int len = s.length();
  cin >> n;
  c.resize(n);
  for (int i = 0; i < n; ++i) cin >> c[i].s >> c[i].l >> c[i].r;
  set<string> res;
  for (int i = 0; i < len; ++i) {
    for (int j = i; j < len; ++j) {
      string t = s.substr(i, j - i + 1);
      if (ok(t)) res.insert(t);
    }
  }
  cout << (int)(res).size() << endl;
}
int main() {
  solve();
  return 0;
}
