#include <bits/stdc++.h>
using namespace std;
int len[16], l[16], r[16], next[2048], slen, n, ans;
char s[2048], p[10][2048];
set<string> S;
string makeString(int a, int b) {
  string ret = "";
  for (int i = a; i <= b; i++) ret += s[i];
  return ret;
}
int main() {
  scanf("%s", s);
  slen = strlen(s);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s%d%d", p[i], &l[i], &r[i]);
    len[i] = strlen(p[i]);
  }
  for (int i = 0; i < slen; i++)
    for (int j = i; j < slen; j++) S.insert(makeString(i, j));
  for (set<string>::iterator it = S.begin(); it != S.end(); it++) {
    string curString = *it;
    int clen = curString.length();
    int f = 0;
    for (int i = 0; i < n; i++) {
      int occ = 0;
      if (clen <= len[i]) {
        for (int j = 0; j < len[i]; j++) {
          int ok = 1;
          for (int k = 0; k < clen; k++) {
            if (p[i][j + k] != curString[k]) {
              ok = 0;
              break;
            }
          }
          if (ok) occ++;
        }
      }
      if (occ >= l[i] && occ <= r[i]) f++;
    }
    if (f == n) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
