#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
const long double eps = 1e-9;
const long double pi = 3.14159265358979323846;
int n;
string s;
string g[20];
int l[20], r[20];
vector<int> arr[20];
vector<int> sums[20];
vector<int> prefix_function(string s) {
  int n = (int)s.length();
  vector<int> pi(n);
  for (int i = 1; i < n; ++i) {
    int j = pi[i - 1];
    while (j > 0 && s[i] != s[j]) j = pi[j - 1];
    if (s[i] == s[j]) ++j;
    pi[i] = j;
  }
  return pi;
}
vector<int> build(int pos) {
  vector<int> pf = prefix_function(g[pos] + "#" + s);
  vector<int> res;
  for (int i = 0; i < int((int)(s).size()); ++i) {
    int ppos = (int)(g[pos]).size() + i + 1;
    if (pf[ppos] == (int)(g[pos]).size())
      res.push_back(1);
    else
      res.push_back(0);
  }
  return res;
}
int main() {
  cin >> s >> n;
  for (int i = 0; i < int(n); ++i) {
    cin >> g[i] >> l[i] >> r[i];
  }
  set<string> answer;
  for (int i = 0; i < int((int)(s).size()); ++i) {
    string t = "";
    for (int j = i; j < (int)(s).size(); j++) {
      t += s[j];
      bool ok = true;
      for (int k = 0; k < int(n); ++k) {
        vector<int> pf = prefix_function(t + "#" + g[k]);
        int cnt = 0;
        for (int r = 0; r < int((int)(pf).size()); ++r) {
          if (pf[r] == (int)(t).size()) cnt++;
        }
        if (!(cnt >= l[k] && cnt <= r[k])) ok = false;
      }
      if (ok) answer.insert(t);
    }
  }
  cout << (int)(answer).size();
}
