#include <bits/stdc++.h>
using namespace std;
int n, nReq;
string req[11];
int L[11], R[11];
int samePrev[50011];
map<string, bool> have;
int getFinalPos(string want, string s) {
  s = "?" + s;
  want = "?" + want;
  samePrev[0] = 0;
  samePrev[1] = 0;
  for (int i = 2; i < want.length(); i++) {
    int t = samePrev[i - 1];
    while (t > 0 && want[t + 1] != want[i]) t = samePrev[t];
    if (want[t + 1] == want[i])
      samePrev[i] = t + 1;
    else
      samePrev[i] = 0;
  }
  want = want + "?";
  int matched = 0;
  int ans = 0;
  for (int i = 1; i < s.length(); i++) {
    while (matched != 0 && want[matched + 1] != s[i])
      matched = samePrev[matched];
    if (want[matched + 1] == s[i]) matched++;
    if (matched == want.size() - 2) ans++;
  }
  return ans;
}
int calc(string sub, string mod) { return getFinalPos(sub, mod); }
bool check(string s) {
  for (int i = 1; i <= nReq; i++) {
    int v = calc(s, req[i]);
    if (!(L[i] <= v && v <= R[i])) return false;
  }
  return true;
}
int MAIN() {
  string s;
  cin >> s;
  cin >> nReq;
  int ans = 0;
  for (int i = 1; i <= nReq; i++) cin >> req[i] >> L[i] >> R[i];
  for (int i = 0; i < s.length(); i++)
    for (int j = i; j < s.length(); j++) {
      string t;
      for (int k = i; k <= j; k++) t += s[k];
      if (have[t]) continue;
      have[t] = true;
      if (check(t)) ans++;
    }
  cout << ans << endl;
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  return MAIN();
}
