#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
inline bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline void read(T &x) {
  char ch = getchar();
  int f = 1;
  x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
int n, l[1000050], r[1000050];
char s[1000050];
struct SAM {
  int last, root, vcnt, ch[1000050][26], fa[1000050], cnt[1000050][12],
      len[1000050];
  long long ans;
  vector<int> adj[1000050];
  void init() { last = root = ++vcnt; }
  void extend(int c, int r) {
    int u = ++vcnt, v = last;
    len[last = u] = len[v] + 1, ++cnt[u][r];
    for (; v && !ch[v][c]; v = fa[v]) ch[v][c] = u;
    if (!v)
      fa[u] = root;
    else if (len[ch[v][c]] == len[v] + 1)
      fa[u] = ch[v][c];
    else {
      int nf = ++vcnt, f = ch[v][c];
      len[nf] = len[v] + 1, memcpy(ch[nf], ch[f], sizeof(ch[nf]));
      fa[nf] = fa[f], fa[f] = fa[u] = nf;
      for (; v && ch[v][c] == f; v = fa[v]) ch[v][c] = nf;
    }
  }
  bool check(int u) {
    for (register int i = 0; i <= n; ++i)
      if (cnt[u][i] < l[i] || cnt[u][i] > r[i]) return 0;
    return 1;
  }
  void dfs(int u) {
    for (auto v : adj[u]) {
      dfs(v);
      for (register int i = 0; i <= n; ++i) cnt[u][i] += cnt[v][i];
    }
    if (check(u)) ans += len[u] - len[fa[u]];
  }
  void solve() {
    for (register int i = 2; i <= vcnt; ++i) adj[fa[i]].push_back(i);
    ans = 0, dfs(1);
  }
} S;
int main() {
  S.init();
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  l[0] = 1, r[0] = 1e9;
  for (register int i = 1; i <= len; ++i) S.extend(s[i] - 'a', 0);
  read(n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%s", s + 1), read(l[i]), read(r[i]);
    S.last = S.root, len = strlen(s + 1);
    for (register int j = 1; j <= len; ++j) S.extend(s[j] - 'a', i);
  }
  S.solve();
  printf("%lld\n", S.ans);
  return 0;
}
