#include <bits/stdc++.h>
using namespace std;
const int ruln = 11;
const int maxn = 2020;
char s[maxn];
char p[maxn];
int cl[maxn];
int cr[maxn];
int clen[maxn];
long long ps[ruln][maxn];
long long p37[maxn];
int ans_size = 0;
long long ans[maxn * maxn];
long long cur[maxn * maxn];
bool isgood[maxn * maxn];
int main(int argc, char **argv) {
  p37[0] = 1;
  for (int i = 1; i < maxn; ++i) {
    p37[i] = 37 * p37[i - 1];
  }
  scanf("%s", s);
  int len = strlen(s);
  for (int l = 0; l < len; ++l) {
    long long chash = 0;
    for (int r = l; r < len; ++r) {
      chash = chash + p37[r - l] * (s[r] - 'a' + 3);
      ans[ans_size++] = chash;
    }
  }
  sort(ans, ans + ans_size);
  ans_size = unique(ans, ans + ans_size) - ans;
  for (int i = 0; i < ans_size; ++i) {
    isgood[i] = true;
  }
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("\n%s %d %d", p, cl + i, cr + i);
    int len = strlen(p);
    int cur_size = 0;
    for (int il = 0; il < len; ++il) {
      long long chash = 0;
      for (int ir = il; ir < len; ++ir) {
        chash = chash + p37[ir - il] * (p[ir] - 'a' + 3);
        cur[cur_size++] = chash;
      }
    }
    sort(cur, cur + cur_size);
    int iter = 0;
    for (int j = 0; j < ans_size; ++j) {
      while (iter < cur_size && cur[iter] < ans[j]) ++iter;
      int cnt = 0;
      while (iter < cur_size && cur[iter] == ans[j]) {
        ++iter;
        ++cnt;
      }
      if (cnt < cl[i] || cnt > cr[i]) {
        isgood[j] = false;
      }
    }
  }
  int ans_res = 0;
  for (int i = 0; i < ans_size; ++i)
    if (isgood[i]) {
      ++ans_res;
    }
  printf("%d\n", ans_res);
  return 0;
}
