#include <bits/stdc++.h>
using namespace std;
string second;
int sa[500005], pos[500005], tmp[500005], lcp[500005], N, gap, freq[500005];
int belong[500005], n, l1[500005], rr[500005], sum[500005][12], M[500005][25];
int logtable[500005];
bool Sufcmp(int i, int j) {
  if (pos[i] != pos[j]) {
    return pos[i] < pos[j];
  }
  i += gap;
  j += gap;
  return (i < N && j < N) ? pos[i] < pos[j] : i > j;
}
void buildSA() {
  N = second.size();
  for (int i = 0; i < N; i++) {
    sa[i] = i;
    pos[i] = second[i];
  }
  tmp[0] = 0;
  for (gap = 1;; gap = (gap << 1)) {
    sort(sa, sa + N, Sufcmp);
    for (int i = 0; i < N - 1; i++)
      tmp[i + 1] = tmp[i] + Sufcmp(sa[i], sa[i + 1]);
    for (int i = 0; i < N; i++) pos[sa[i]] = tmp[i];
    if (tmp[N - 1] == N - 1) break;
  }
}
void buildLCP() {
  N = second.size();
  lcp[0] = 0;
  for (int i = 0, k = 0; i < N; i++) {
    if (pos[i] != N - 1) {
      for (int j = sa[pos[i] + 1]; second[i + k] == second[j + k];) k++;
      lcp[pos[i] + 1] = k;
      if (k) k--;
    }
  }
}
void process2() {
  int i, j;
  for (i = 0; i < N; i++) M[i][0] = lcp[i];
  for (j = 1; 1 << j <= N; j++)
    for (i = 0; i + (1 << j) - 1 < N; i++)
      if (M[i][j - 1] < M[i + (1 << (j - 1))][j - 1])
        M[i][j] = M[i][j - 1];
      else
        M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
inline int rmq(int i, int j) {
  int k = logtable[j - i + 1];
  int x = M[i][k];
  int y = M[j - (1 << k) + 1][k];
  return min(x, y);
}
inline int get(int i, int j) {
  if (i > N - 1 || j > N - 1 || i < 0 || j < 0 || j < i) assert(false);
  if (i == j) return N - sa[i];
  return rmq(i + 1, j);
}
int okl(int index, int len) {
  int lo, mid, hi, l, r, got;
  hi = index;
  lo = -1;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    if (get(mid, index) >= len)
      hi = mid;
    else
      lo = mid;
  }
  l = hi;
  lo = index;
  hi = N;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    if (get(index, mid) >= len)
      lo = mid;
    else
      hi = mid;
  }
  r = lo;
  assert(r >= l);
  for (int i = 1; i <= n; i++) {
    got = sum[r][i];
    if (l > 0) got -= sum[l - 1][i];
    assert(got >= 0);
    if (got < l1[i]) return 0;
  }
  return 1;
}
int okr(int index, int len) {
  int lo, mid, hi, l, r, got;
  hi = index;
  lo = -1;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    if (get(mid, index) >= len)
      hi = mid;
    else
      lo = mid;
  }
  l = hi;
  lo = index;
  hi = N;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    if (get(index, mid) >= len)
      lo = mid;
    else
      hi = mid;
  }
  r = lo;
  for (int i = 1; i <= n; i++) {
    got = sum[r][i];
    if (l > 0) got -= sum[l - 1][i];
    if (got > rr[i]) return 0;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  int i, j, l, L, x, y, ans = 0, mid, lo, hi, r;
  string s;
  cin >> second;
  L = second.length();
  l = second.length();
  for (i = 0; i < l; i++) belong[i] = 0;
  second = second + '#';
  l = second.length();
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s;
    cin >> l1[i] >> rr[i];
    second = second + s;
    for (j = l; j < second.length(); j++) belong[j] = i;
    second = second + '#';
    l = second.length();
  }
  N = second.size();
  buildSA();
  buildLCP();
  int p = 1;
  int Lg = 0;
  while (p / 2 <= N) {
    for (int i = p; i <= p * 2 - 1 and i <= N; ++i) logtable[i] = Lg;
    Lg++;
    p *= 2;
  }
  process2();
  for (i = 0; i < N; i++) {
    for (j = 1; j <= n; j++) {
      if (i > 0) sum[i][j] = sum[i - 1][j];
    }
    if (second[sa[i]] == '#') continue;
    sum[i][belong[sa[i]]]++;
  }
  int pre = -1, len;
  for (i = 0; i < N; i++) {
    if (belong[sa[i]] != 0 || second[sa[i]] == '#') continue;
    if (pre == -1)
      len = 0;
    else
      len = get(pre, i);
    pre = i;
    assert(sa[i] >= 0 && sa[i] < L);
    lo = len + 1;
    hi = L - sa[i] + 1;
    if (!okl(i, lo)) continue;
    while (hi - lo > 1) {
      mid = (lo + hi) / 2;
      if (okl(i, mid))
        lo = mid;
      else
        hi = mid;
    }
    r = sa[i] + lo - 1;
    assert(r < L);
    hi = L - sa[i];
    lo = len;
    if (!okr(i, hi)) continue;
    while (hi - lo > 1) {
      mid = (lo + hi) / 2;
      if (okr(i, mid))
        hi = mid;
      else
        lo = mid;
    }
    l = sa[i] + hi - 1;
    assert(l < L);
    if (l <= r) ans += r - l + 1;
  }
  cout << ans;
  return 0;
}
