#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10, MOD = 1000 * 1000 * 1000 + 7;
string Candid[maxn];
bool Can[maxn];
set<string> Set;
string s;
inline string Sub(int l, int r) {
  int i;
  string ans = "";
  for (i = l; i <= r; i++) ans += s[i];
  return ans;
}
void KMPpreprocess(string pattern, vector<int> &back) {
  int i, j;
  i = 0;
  j = -1;
  back.push_back(-1);
  while (i < pattern.size()) {
    while (j >= 0 && pattern[i] != pattern[j]) j = back[j];
    i++;
    j++;
    back.push_back(j);
  }
}
int KMPsearch(vector<int> back, string pattern, string way) {
  int i, j, occ;
  occ = i = j = 0;
  while (i < way.size()) {
    while (j >= 0 && way[i] != pattern[j]) j = back[j];
    i++;
    j++;
    if (j == pattern.size()) {
      occ++;
      j = back[j];
    }
  }
  return occ;
}
int main() {
  int n, left[20], right[20], i, l, r;
  string p[20];
  vector<int> ba;
  cin >> s >> n;
  for (l = 0; l < s.size(); l++) {
    for (r = l; r < s.size(); r++) {
      Set.insert(Sub(l, r));
    }
  }
  set<string>::iterator itr;
  int t;
  t = 0;
  for (itr = Set.begin(); itr != Set.end(); itr++) {
    Candid[t++] = *itr;
  }
  for (i = 0; i < t; i++) Can[i] = true;
  for (i = 0; i < n; i++) cin >> p[i] >> left[i] >> right[i];
  int temp, j;
  for (j = 0; j < t; j++) {
    ba.clear();
    KMPpreprocess(Candid[j], ba);
    for (i = 0; i < n; i++) {
      if (Can[j]) {
        temp = KMPsearch(ba, Candid[j], p[i]);
        if (temp < left[i] || temp > right[i]) Can[j] = false;
      }
    }
  }
  int ans = 0;
  for (i = 0; i < t; i++) {
    if (Can[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}
