#include <bits/stdc++.h>
using namespace std;
int T[1000];
void computeT(string &Needle) {
  int i = 0, j = -1;
  T[i] = j;
  while (i < Needle.size()) {
    while (j >= 0 && Needle[i] != Needle[j]) j = T[j];
    T[++i] = ++j;
  }
}
int findOcurrence(string &Needle, string &Hay) {
  int i = 0, j = 0, r = 0;
  computeT(Needle);
  while (i < Hay.size()) {
    while (j >= 0 && Hay[i] != Needle[j]) j = T[j];
    i++;
    j++;
    if (j == Needle.size()) {
      r++;
      j = T[j];
    }
  }
  return r;
}
string P[20];
int L[20], R[20];
int main() {
  string A;
  cin >> A;
  set<string> S;
  for (int i = 0; i < A.size(); ++i)
    for (int j = i; j < A.size(); ++j) S.insert(A.substr(i, j - i + 1));
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> P[i] >> L[i] >> R[i];
  int s = 0;
  for (set<string>::iterator it = S.begin(); it != S.end(); ++it) {
    int ok = 1;
    for (int i = 0; i < N && ok; ++i) {
      string a = *it;
      int t = findOcurrence(a, P[i]);
      if (t < L[i] || t > R[i]) ok = 0;
    }
    s += ok;
  }
  cout << s << endl;
}
