#include <bits/stdc++.h>
using namespace std;
const int maxn = 550000;
int down[11], up[11];
char s[maxn + 5];
int sz = 0, len, last = 0, n;
int maxlen[2 * maxn + 50], minlen[2 * maxn + 50], trans[2 * maxn + 50][26],
    slink[2 * maxn + 50], endpos[2 * maxn + 50][11];
int sa[maxn * 2 + 5], cnt[maxn * 2 + 5];
int build(int _maxlen, int _minlen, int* _trans, int _slink) {
  maxlen[++sz] = _maxlen;
  minlen[sz] = _minlen;
  for (int i = 0; i < 26; ++i)
    if (_trans == NULL)
      trans[sz][i] = -1;
    else
      trans[sz][i] = _trans[i];
  slink[sz] = _slink;
  return sz;
}
int add(char ch, int u) {
  int c = ch - 'a';
  if (trans[u][c] != -1 && maxlen[u] + 1 == maxlen[trans[u][c]])
    return trans[u][c];
  int z = build(maxlen[u] + 1, -1, NULL, -1);
  int v = u;
  while (v != -1 && trans[v][c] == -1) trans[v][c] = z, v = slink[v];
  if (v == -1) {
    minlen[z] = 1;
    slink[z] = 0;
    return z;
  }
  int x = trans[v][c];
  if (maxlen[v] + 1 == maxlen[x]) {
    minlen[z] = maxlen[x] + 1;
    slink[z] = x;
    return z;
  }
  int y = build(maxlen[v] + 1, -1, trans[x], slink[x]);
  slink[y] = slink[x];
  minlen[x] = maxlen[y] + 1;
  slink[x] = y;
  minlen[z] = maxlen[y] + 1;
  slink[z] = y;
  int w = v;
  while (w != -1 && trans[w][c] == x) trans[w][c] = y, w = slink[w];
  minlen[y] = maxlen[slink[y]] + 1;
  return z;
}
int main() {
  scanf("%s", s);
  len = strlen(s);
  for (int i = 0; i < 26; ++i) trans[0][i] = slink[0] = -1;
  maxlen[0] = minlen[0] = 0;
  sz = 0;
  last = 0;
  for (int i = 0; i < len; ++i) {
    last = add(s[i], last);
    endpos[last][0] = 1;
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%d%d", s, &down[i], &up[i]);
    len = strlen(s);
    last = 0;
    for (int j = 0; j < len; ++j) {
      last = add(s[j], last);
      endpos[last][i] = 1;
    }
  }
  for (int i = 1; i <= sz; ++i) ++cnt[maxlen[i]];
  for (int i = 2; i <= sz; ++i) cnt[i] += cnt[i - 1];
  for (int i = 1; i <= sz; ++i) sa[cnt[maxlen[i]]--] = i;
  for (int i = sz; i >= 1; --i) {
    int u = sa[i];
    for (int j = 0; j <= n; ++j) endpos[slink[u]][j] += endpos[u][j];
  }
  int ans = 0;
  for (int i = 1; i <= sz; ++i)
    if (endpos[i][0]) {
      bool flag = true;
      for (int j = 1; j <= n; ++j)
        if (endpos[i][j] < down[j] || endpos[i][j] > up[j]) flag = false;
      if (flag) ans += maxlen[i] - minlen[i] + 1;
    }
  cout << ans << endl;
  return 0;
}
