#include <bits/stdc++.h>
using namespace std;
struct E {
  int v, n;
} G[1000010];
int m, k;
int cnt, point[1000010];
int pl[12], pr[12];
void adde(int u, int v) { G[++cnt] = (E){v, point[u]}, point[u] = cnt; }
long long ans;
bool vis[1000010];
struct SAM {
  static const int K = 26;
  int rt, la, nodes;
  int len[1000010], n[1000010][K + 1], pa[1000010], sz[12][1000010];
  void init() {
    nodes = 0;
    rt = la = newnode(0);
  }
  int newnode(int pl) {
    int i = ++nodes;
    len[i] = pl;
    return i;
  }
  void ins(int w, int d) {
    int p = la, np = newnode(len[p] + 1);
    la = np;
    if (w < 26) sz[d][np] = 1;
    while (p && !n[p][w]) n[p][w] = np, p = pa[p];
    if (!p)
      pa[np] = rt;
    else {
      int q = n[p][w];
      if (len[q] == len[p] + 1)
        pa[np] = q;
      else {
        int nq = newnode(len[p] + 1);
        memcpy(n[nq], n[q], sizeof(n[q]));
        pa[nq] = pa[q];
        pa[q] = pa[np] = nq;
        while (p && n[p][w] == q) n[p][w] = nq, p = pa[p];
      }
    }
  }
  void getsz() {
    for (int i = 2, lim = nodes; i <= lim; ++i) adde(pa[i], i);
    dfs(rt);
  }
  void dfs1(int u) {
    vis[u] = 1;
    for (int i = 0, lim = K - 1; i <= lim; ++i) {
      if (n[u][i]) dfs1(n[u][i]);
    }
  }
  void dfs(int u) {
    for (int i = point[u]; i; i = G[i].n) {
      int v = G[i].v;
      dfs(v);
      for (int j = 0, lim = k; j <= lim; ++j) sz[j][u] += sz[j][v];
    }
    if (sz[0][u]) {
      int ok = 1;
      for (int j = 0, lim = k - 1; j <= lim; ++j)
        if (sz[j + 1][u] > pr[j + 1] || sz[j + 1][u] < pl[j + 1]) ok = 0;
      if (ok) ans += (long long)(len[u] - len[pa[u]]);
    }
  }
  void debug() {
    for (int i = 1, lim = nodes; i <= lim; ++i) {
      printf("i = %d, pa = %d, minlen = %d, maxlen = %d\n", i, pa[i],
             len[pa[i]] + 1, len[i]);
    }
    for (int i = 1, lim = nodes; i <= lim; ++i) {
      for (int j = 0, lim = K; j <= lim; ++j)
        if (n[i][j]) printf("%d %d %c\n", i, n[i][j], j + 'a');
    }
  }
} sam;
char s[1000010];
int main() {
  scanf("%s", s);
  m = strlen(s);
  sam.init();
  for (int j = 0, lim = m - 1; j <= lim; ++j) sam.ins(s[j] - 'a', 0);
  sam.ins(26, 0);
  scanf("%d", &k);
  for (int i = 0, lim = k - 1; i <= lim; ++i) {
    scanf("%s", s);
    scanf("%d", &pl[i + 1]), scanf("%d", &pr[i + 1]);
    m = strlen(s);
    for (int j = 0, lim = m - 1; j <= lim; ++j) sam.ins(s[j] - 'a', i + 1);
    sam.ins(26, i + 1);
  }
  sam.getsz();
  printf("%I64d", (ans));
  return 0;
}
