#include <bits/stdc++.h>
using namespace std;
long long mul1 = 239017;
long long mul2 = 239021;
long long mod1 = 1000000007;
long long mod2 = 1000000021;
const int MAXN = 1 << 23;
unsigned long long h[MAXN + 1000];
int cnt[MAXN + 1000];
char s[100005];
void gen_hashes(void) {
  int l = strlen(s);
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < l; i++) {
    const long long hash1 = 0;
    long long hash2 = 0;
    for (int j = i; j < l; j++) {
      hash2 = hash2 * mul2 + s[j];
      unsigned long long hash = ((hash1 << 32) + hash2);
      int pos = hash & (MAXN - 1);
      while (cnt[pos] && h[pos] != hash) {
        pos++;
      }
      h[pos] = hash;
      cnt[pos]++;
    }
  }
}
unsigned long long res[2100000];
int main(void) {
  int n;
  scanf("%s%d", s, &n);
  int resl = 0;
  gen_hashes();
  for (int i = 0; i < MAXN + 1000; i++) {
    if (cnt[i]) {
      res[resl++] = h[i];
    }
  }
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%s%d%d", s, &l, &r);
    r -= l;
    gen_hashes();
    int nl = 0;
    for (int i = 0; i < resl; i++) {
      unsigned long long hash = res[i];
      int pos = hash & (MAXN - 1);
      while (cnt[pos] && h[pos] != hash) {
        pos++;
      }
      if ((unsigned int)(cnt[pos] - l) <= (unsigned int)r) {
        res[nl++] = hash;
      }
    }
    resl = nl;
  }
  printf("%d\n", resl);
  return 0;
}
