#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long inf = 1ll << 62;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
const int maxn = 50005 * 11 * 2;
int n, l[13], r[13];
char s[50005];
struct SAM {
  struct node {
    int max, next[27], link;
  } T[maxn];
  int start, last, tot;
  int cnt[maxn][12];
  SAM() {
    tot = 0;
    start = last = newnode(0);
  }
  int newnode(int max) {
    int x = ++tot;
    T[x].link = 0;
    memset(T[x].next, 0, sizeof(T[x].next));
    memset(cnt[x], 0, sizeof(cnt[x]));
    T[x].max = max;
    return x;
  }
  void extend(int k, int c) {
    int v = last;
    if (T[v].max + 1 == T[T[v].next[c]].max) {
      last = T[v].next[c];
      cnt[last][k]++;
      return;
    }
    int u = newnode(T[v].max + 1);
    for (; v && T[v].next[c] == 0; v = T[v].link) T[v].next[c] = u;
    if (!v) {
      T[u].link = start;
    } else if (T[v].max + 1 == T[T[v].next[c]].max) {
      T[u].link = T[v].next[c];
    } else {
      int o = T[v].next[c], n = newnode(T[v].max + 1);
      for (register int k = (0); k < int(27); ++k) T[n].next[k] = T[o].next[k];
      T[n].link = T[o].link;
      T[o].link = T[u].link = n;
      for (; v && T[v].next[c] == o; v = T[v].link) T[v].next[c] = n;
      ;
    }
    last = u;
    cnt[last][k]++;
  }
  vector<int> V[maxn];
  void dfs(int u) {
    for (auto v : V[u]) {
      dfs(v);
      for (register int k = (0); k <= int(n); ++k) cnt[u][k] += cnt[v][k];
    }
  }
  void topsort() {
    for (register int i = (1); i <= int(tot); ++i) V[i].clear();
    for (int i = 2; i <= tot; ++i) V[T[i].link].push_back(i);
    dfs(1);
  }
  void solve() {
    int ans = 0;
    for (int i = 2; i <= tot; ++i) {
      bool flag = true;
      flag &= cnt[i][0] > 0;
      for (register int k = (1); k <= int(n); ++k)
        flag &= ((l[k] <= cnt[i][k] && cnt[i][k] <= r[k]));
      if (flag) ans += T[i].max - T[T[i].link].max;
    }
    writeln(ans);
  }
} sam;
int main() {
  scanf("%s", s);
  for (int i = 0; s[i]; ++i) sam.extend(0, s[i] - 'a');
  n = read();
  for (register int i = (1); i <= int(n); ++i) {
    scanf("%s", s);
    l[i] = read(), r[i] = read();
    sam.last = sam.start;
    for (int j = 0; s[j]; ++j) sam.extend(i, s[j] - 'a');
  }
  sam.topsort();
  sam.solve();
  return 0;
}
