#include <bits/stdc++.h>
using namespace std;
int err;
int bitc(long long r) { return r == 0 ? 0 : (bitc(r >> 1) + (r & 1)); }
long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
string cts(char c) {
  string s = "";
  s += c;
  return s;
}
char buf[1000000];
string getLine() {
  string s;
  while (!feof(stdin)) {
    char c = fgetc(stdin);
    if (c == 13) continue;
    if (c == 10) return s;
    s += c;
  }
  return s;
}
int getNum() {
  string s = getLine();
  return atoi(s.c_str());
}
vector<int> parsevi(string s) {
  s = s + " ";
  int q = 0;
  bool minus = false;
  vector<int> res;
  for (typeof(0) l = (0); l < ((int(s.size()))); ++l) {
    if (s[l] == ' ') {
      res.push_back(minus ? -q : q);
      q = 0;
      minus = false;
    } else if (s[l] == '-') {
      minus = true;
    } else {
      q = q * 10 + s[l] - '0';
    }
  }
  return res;
}
int Cases, cnum;
int N;
char S[5000];
string xS;
int ppow[5000];
int Spow[5000];
char P[20][5000];
string xP[20];
int Ppow[20][5000];
map<string, int> occ[20];
int pmin[20], pmax[20];
set<string> se;
int qocc(string t, string pat) {
  int L = (int(pat.size())) - (int(t.size()));
  int res = 0;
  for (typeof(0) k = (0); k < (L + 1); ++k)
    if (pat.substr(k, (int(t.size()))) == t) res++;
  return res;
}
void solveCase() {
  int res = 0;
  ppow[0] = 1;
  for (typeof(1) v = (1); v < (5000); ++v) ppow[v] = ppow[v - 1] * 123591;
  err = scanf("%s", S);
  xS = S;
  err = scanf("%d", &N);
  for (typeof(0) n = (0); n < (N); ++n) {
    err = scanf("%s%d%d", P[n], &pmin[n], &pmax[n]);
    xP[n] = P[n];
    for (typeof(0) r = (0); r < ((int(xP[n].size())) + 1); ++r)
      for (typeof(0) l = (0); l < (r); ++l) {
        string t = xP[n].substr(l, r - l);
        occ[n][t]++;
      }
  }
  int Len = (int(xS.size()));
  for (typeof(0) r = (0); r < (Len + 1); ++r)
    for (typeof(0) l = (0); l < (r); ++l) {
      string t = xS.substr(l, r - l);
      for (typeof(0) n = (0); n < (N); ++n) {
        int o = occ[n][t];
        if (o < pmin[n] || o > pmax[n]) goto nextlr;
      }
      se.insert(t);
    nextlr:;
    }
  printf("%d\n", (int(se.size())));
}
int main() {
  if (1)
    Cases = 1;
  else if (0) {
    string Nstr = getLine();
    Cases = atoi(Nstr.c_str());
  } else {
    err = scanf("%d", &Cases);
  }
  for (cnum = 1; cnum <= Cases; cnum++) solveCase();
  return 0;
}
