#include <bits/stdc++.h>
using namespace std;
const int MAX = 2001;
const long long B = 139;
char s[MAX];
char group[10][MAX];
int con[10][2];
int N;
vector<long long> cnt[10];
int main() {
  int i, j;
  scanf("%s%d", s, &N);
  for (i = 0; i < N; ++i) {
    scanf("%s%d%d", group[i], &con[i][0], &con[i][1]);
    cnt[i].reserve(strlen(group[i]) * strlen(group[i]));
  }
  for (int t = 0; t < N; ++t) {
    int len = strlen(group[t]);
    for (i = 0; i < len; ++i) {
      long long hash = 0;
      for (j = i; j < len; ++j) {
        hash = hash * B + group[t][j];
        cnt[t].push_back(hash);
      }
    }
    sort(cnt[t].begin(), cnt[t].end());
  }
  int ans = 0, len = strlen(s);
  set<long long> mark;
  for (i = 0; i < len; ++i) {
    long long hash = 0;
    for (j = i; j < len; ++j) {
      hash = hash * B + s[j];
      bool ok = true;
      for (int t = 0; t < N && ok; ++t) {
        int c = upper_bound(cnt[t].begin(), cnt[t].end(), hash) -
                lower_bound(cnt[t].begin(), cnt[t].end(), hash);
        ok = c >= con[t][0] && c <= con[t][1];
      }
      if (ok && mark.insert(hash).second) {
        ++ans;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
