#include <bits/stdc++.h>
using namespace std;
const int maxn = 610000;
char s[maxn];
int rep[maxn], cnt[maxn][12];
int n, slen, lenn;
int aa[12], bb[12];
int wa[maxn], wb[maxn], wv[maxn], wt[maxn];
bool cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(int *r, int *sa, int n, int m) {
  int i, j, p, *x = wa, *y = wb, *t;
  for (i = 0; i < m; i++) wt[i] = 0;
  for (i = 0; i < n; i++) wt[x[i] = r[i]]++;
  for (i = 1; i < m; i++) wt[i] += wt[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--wt[x[i]]] = i;
  for (j = 1, p = 1; p < n; j *= 2, m = p) {
    for (p = 0, i = n - j; i < n; i++) y[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    for (i = 0; i < n; i++) wv[i] = x[y[i]];
    for (i = 0; i < m; i++) wt[i] = 0;
    for (i = 0; i < n; i++) wt[wv[i]]++;
    for (i = 1; i < m; i++) wt[i] += wt[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--wt[wv[i]]] = y[i];
    for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; i++)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
  }
}
int sa[maxn], r[maxn], rrank[maxn], height[maxn];
void calheight(int *r, int *sa, int n) {
  int i, j, k = 0;
  for (i = 1; i <= n; i++) rrank[sa[i]] = i;
  for (i = 0; i < n; height[rrank[i++]] = k)
    for (k ? k-- : 0, j = sa[rrank[i] - 1]; r[i + k] == r[j + k]; k++)
      ;
}
int mm[maxn], best[20][maxn];
void initRMQ(int n) {
  int i, j, a, b;
  for (mm[0] = -1, i = 1; i <= n; i++)
    mm[i] = ((i & (i - 1)) == 0) ? mm[i - 1] + 1 : mm[i - 1];
  for (i = 1; i <= n; i++) best[0][i] = i;
  for (i = 1; i <= mm[n]; i++)
    for (j = 1; j <= n + 1 - (1 << i); j++) {
      a = best[i - 1][j];
      b = best[i - 1][j + (1 << (i - 1))];
      if (height[a] < height[b])
        best[i][j] = a;
      else
        best[i][j] = b;
    }
}
int askRMQ(int a, int b) {
  int t = mm[b - a + 1];
  b -= (1 << t) - 1;
  a = best[t][a];
  b = best[t][b];
  return height[a] < height[b] ? a : b;
}
int lcp(int a, int b) {
  a = rrank[a];
  b = rrank[b];
  if (a > b) swap(a, b);
  return height[askRMQ(a + 1, b)];
}
int lef[51000], rig[51000];
void leninit() {
  slen = strlen(s);
  for (int i = 0; i < slen; ++i) r[i] = s[i] - 'a' + 1;
  r[slen] = 0;
  da(r, sa, slen + 1, 33);
  calheight(r, sa, slen);
  for (int i = 1; i <= slen; ++i) {
    lef[sa[i]] = height[i];
    rig[sa[i]] = slen - sa[i];
  }
}
void myinit() {
  lenn = slen;
  for (int i = 1; i <= n; ++i) {
    r[lenn++] = i + 30;
    scanf("%s %d %d", s, &aa[i], &bb[i]);
    for (int j = 0; s[j]; ++j, ++lenn) {
      r[lenn] = s[j] - 'a' + 1;
      rep[lenn] = i;
    }
  }
  r[lenn] = 0;
  da(r, sa, lenn + 1, 44);
  calheight(r, sa, lenn);
  initRMQ(lenn);
  for (int i = 1; i <= lenn; ++i) {
    for (int j = 1; j <= n; ++j) cnt[i][j] = cnt[i - 1][j];
    cnt[i][rep[sa[i]]]++;
  }
}
bool upaa(int idx, int len) {
  int nidx = rrank[idx];
  int rx = nidx, ry = lenn;
  while (ry > rx) {
    int rm = ry - (ry - rx) / 2;
    if (lcp(sa[nidx], sa[rm]) >= len)
      rx = rm;
    else
      ry = rm - 1;
  }
  int lx = 0, ly = nidx;
  while (ly > lx) {
    int lm = lx + (ly - lx) / 2;
    if (lcp(sa[lm], sa[nidx]) >= len)
      ly = lm;
    else
      lx = lm + 1;
  }
  for (int i = 1; i <= n; ++i) {
    int num = cnt[rx][i] - (ly == 0 ? 0 : cnt[ly - 1][i]);
    if (num < aa[i]) return false;
  }
  return true;
}
bool dnbb(int idx, int len) {
  int nidx = rrank[idx];
  int rx = nidx, ry = lenn;
  while (ry > rx) {
    int rm = ry - (ry - rx) / 2;
    if (lcp(sa[nidx], sa[rm]) >= len)
      rx = rm;
    else
      ry = rm - 1;
  }
  int lx = 0, ly = nidx;
  while (ly > lx) {
    int lm = lx + (ly - lx) / 2;
    if (lcp(sa[lm], sa[nidx]) >= len)
      ly = lm;
    else
      lx = lm + 1;
  }
  for (int i = 1; i <= n; ++i) {
    int num = cnt[rx][i] - (ly == 0 ? 0 : cnt[ly - 1][i]);
    if (num > bb[i]) return false;
  }
  return true;
}
int half(int idx) {
  int ux = lef[idx], uy = rig[idx];
  while (uy > ux) {
    int m = uy - (uy - ux) / 2;
    if (upaa(idx, m))
      ux = m;
    else
      uy = m - 1;
  }
  int dx = lef[idx], dy = rig[idx];
  while (dy > dx) {
    int m = dy - (dy - dx) / 2;
    if (!dnbb(idx, m))
      dx = m;
    else
      dy = m - 1;
  }
  return ux - min(ux, dx);
}
void debug() {
  for (int i = 0; i <= lenn; ++i) {
    printf("%d ", sa[i]);
  }
  puts("");
  for (int i = 0; i <= lenn; ++i) {
    printf("%d ", rep[i]);
  }
  puts("");
  for (int i = 0; i <= lenn; ++i) printf("%d ", cnt[i][1]);
  puts("");
}
int main() {
  scanf("%s", s);
  leninit();
  scanf("%d", &n);
  myinit();
  long long res = 0;
  for (int i = 0; i < slen; ++i)
    if (rig[i] > lef[i]) res += half(i);
  cout << res << endl;
  return 0;
}
