#include <bits/stdc++.h>
using namespace std;
string s, p[11], t;
pair<int, int> lim[11];
int n;
vector<string> ans;
int occ(string a, string b) {
  if (a.length() > b.length()) return 0;
  int res = 0;
  for (int i = 0; i < (b.length() - a.length() + 1); ++i)
    if (b.compare(i, a.length(), a) == 0) ++res;
  return res;
}
int main() {
  cin >> s;
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) cin >> p[i] >> lim[i].first >> lim[i].second;
  for (int len = (1); len <= (s.length()); ++len) {
    for (int start = (0); start <= (s.length() - len); ++start) {
      t = s.substr(start, len);
      bool good = true;
      for (int i = 0; i < (n); ++i) {
        int occurence = occ(t, p[i]);
        if (occurence < lim[i].first || lim[i].second < occurence) {
          good = false;
          break;
        }
      }
      if (good) ans.push_back(t);
    }
  }
  sort((ans).begin(), (ans).end());
  int nans = 0;
  for (int i = 0; i < (((int)(ans).size())); ++i)
    if (i == 0)
      nans++;
    else if (ans[i].compare(ans[i - 1]))
      nans++;
  printf("%d\n", nans);
  return 0;
}
