#include <bits/stdc++.h>
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
using namespace std;
long long base1 = 233, base2 = 2333;
long long MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
char s[2010], t[2010];
int l[11], r[11], num[11];
long long a[11][2000010];
int main() {
  int n, m;
  int ans = 0;
  scanf("%s", s + 1);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", t + 1);
    scanf("%d%d", &l[i], &r[i]);
    m = strlen(t + 1);
    for (int j = 1; j <= m; ++j) {
      long long h1 = 0, h2 = 0;
      for (int k = j; k <= m; ++k) {
        h1 = (h1 * base1 + t[k]) % MOD1;
        h2 = (h2 * base2 + t[k]) % MOD2;
        a[i][num[i]++] = h1 * MOD1 + h2;
      }
    }
    sort(a[i], a[i] + num[i]);
  }
  m = strlen(s + 1);
  for (int i = 1; i <= m; ++i) {
    long long h1 = 0, h2 = 0;
    for (int j = i; j <= m; ++j) {
      h1 = (h1 * base1 + s[j]) % MOD1;
      h2 = (h2 * base2 + s[j]) % MOD2;
      a[0][num[0]++] = h1 * MOD1 + h2;
    }
  }
  sort(a[0], a[0] + num[0]);
  m = unique(a[0], a[0] + num[0]) - a[0];
  for (int j = 0; j < m; ++j) {
    bool ok = true;
    long long x = a[0][j];
    for (int i = 1; i <= n; ++i) {
      int p = lower_bound(a[i], a[i] + num[i], x) - a[i];
      int q = upper_bound(a[i], a[i] + num[i], x) - a[i];
      int tmp = q - p;
      if (tmp < l[i] || tmp > r[i]) {
        ok = false;
        break;
      }
    }
    ans += ok;
  }
  printf("%d", ans);
  return 0;
}
