#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
pair<int, int> M[8] = {make_pair(0, 1),  make_pair(1, 0),  make_pair(-1, 0),
                       make_pair(0, -1), make_pair(-1, 1), make_pair(-1, -1),
                       make_pair(1, -1), make_pair(1, 1)};
char s[2005];
string lol[2005];
pair<int, int> req[2005];
int p[2005];
set<string> kya;
int main() {
  gets(s);
  int len = strlen(s);
  int k;
  cin >> k;
  for (int(a) = (1); (a) <= (k); (a)++) {
    cin >> lol[a] >> req[a].first >> req[a].second;
  }
  int ans = 0;
  for (int(a) = (0); (a) <= (len - 1); (a)++) {
    for (int(b) = (a); (b) <= (len - 1); (b)++) {
      int j = -1;
      p[0] = -1;
      int ls = b - a;
      for (int(i) = (0); (i) <= (ls); (i)++) {
        while (j >= 0 && s[a + i] != s[a + j]) j = p[j];
        j++;
        p[i + 1] = j;
      }
      bool bisa = 1;
      for (int(c) = (1); (c) <= (k); (c)++) {
        int j = 0;
        int found = 0;
        for (int(i) = (0); (i) <= (lol[c].length() - 1); (i)++) {
          while (j >= 0 && lol[c][i] != s[a + j]) j = p[j];
          j++;
          if (j == ls + 1) {
            found++;
            j = p[j];
          }
        }
        if (req[c].first <= found && found <= req[c].second)
          ;
        else {
          bisa = 0;
          break;
        }
      }
      if (bisa) {
        string y = "";
        for (int(o) = (a); (o) <= (b); (o)++) y += s[o];
        kya.insert(y);
        ans++;
      }
    }
  }
  cout << (int)kya.size() << endl;
}
