#include <bits/stdc++.h>
using namespace std;
namespace SA {
const int maxn = 600000;
int len[maxn], suf[maxn], nxt[maxn][27];
int last = 1, sz = 2;
int cnt[maxn][11];
int newV(int l, int s) {
  len[sz] = l;
  suf[sz] = s;
  return sz++;
}
void addch(int ch, int tp) {
  int p = last;
  last = newV(len[last] + 1, 0);
  nxt[p][ch] = last;
  cnt[last][tp]++;
  for (p = suf[p]; !nxt[p][ch]; p = suf[p]) nxt[p][ch] = last;
  if (!p) return void(suf[last] = 1);
  int q = nxt[p][ch];
  if (len[p] + 1 == len[q]) return void(suf[last] = q);
  int r = newV(len[p] + 1, suf[q]);
  suf[q] = suf[last] = r;
  memcpy(nxt[r], nxt[q], sizeof nxt[q]);
  for (; nxt[p][ch] == q; p = suf[p]) nxt[p][ch] = r;
}
};  // namespace SA
int n;
string s;
string t[11];
int l[11], r[11];
int hv[SA::maxn];
vector<int> q;
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  cin >> n;
  for (int i = 0; i < int(n); i++) cin >> t[i] >> l[i] >> r[i];
  for (int i = 0; i < int(s.size()); i++) SA::addch(s[i] - 'a', 0);
  for (int i = 0; i < int(n); i++) {
    SA::addch(26, i + 1);
    for (int j = 0; j < int(t[i].size()); j++) SA::addch(t[i][j] - 'a', i + 1);
  }
  int qb = 0;
  for (int v = 0; v < int(SA::sz); v++) hv[SA::suf[v]]++;
  int ans = 0;
  for (int v = 0; v < int(SA::sz); v++)
    if (!hv[v]) q.push_back(v);
  while (qb < (int)q.size()) {
    int v = q[qb++];
    int sf = SA::suf[v];
    bool fl = SA::cnt[v][0] > 0;
    for (int i = 0; i < int(n); i++)
      fl &= (l[i] <= SA::cnt[v][i + 1]) && (SA::cnt[v][i + 1] <= r[i]);
    if (fl) ans += (SA::len[v] - SA::len[sf]);
    for (int i = 0; i < int(n + 1); i++) SA::cnt[sf][i] += SA::cnt[v][i];
    hv[sf]--;
    if (hv[sf] == 0) q.push_back(sf);
  }
  cout << ans << endl;
}
