#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
const int LGN = 20;
int r[LGN][MAXN];
vector<int> suf;
int lcp(int a, int b) {
  int ans = 0;
  for (int i = LGN - 1; i >= 0 && a < suf.size() && b < suf.size(); i--) {
    if (r[i][a] == r[i][b]) {
      ans += 1 << i;
      a += 1 << i;
      b += 1 << i;
    }
  }
  return ans;
}
void calSuf(string s) {
  int n = s.size();
  for (int i = 0; i < n; i++) r[0][i] = s[i];
  vector<pair<pair<int, int>, int> > v(n);
  for (int i = 1; i < LGN; i++) {
    for (int j = 0; j < n; j++)
      v[j] = make_pair(
          make_pair(r[i - 1][j],
                    j + (1 << (i - 1)) < n ? r[i - 1][j + (1 << (i - 1))] : -1),
          j);
    sort((v).begin(), (v).end());
    for (int j = 0; j < n; j++)
      r[i][v[j].second] =
          (j && v[j - 1].first == v[j].first) ? r[i][v[j - 1].second] : j;
  }
  suf.resize(n);
  for (int i = 0; i < n; i++) suf[i] = v[i].second;
}
pair<int, int> bound(int x, int l) {
  pair<int, int> ans;
  int d = x, u = suf.size();
  while (d < u - 1) {
    int mid = (d + u) / 2;
    (lcp(suf[x], suf[mid]) >= l) ? d = mid : u = mid;
  }
  ans.second = d;
  d = -1, u = x;
  while (d < u - 1) {
    int mid = (d + u) / 2;
    (lcp(suf[x], suf[mid]) >= l) ? u = mid : d = mid;
  }
  ans.first = u;
  return ans;
}
int psum[MAXN];
pair<int, int> cs[MAXN];
int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < MAXN; i++) cs[i] = make_pair(1, n - i);
  int q;
  cin >> q;
  while (q--) {
    string t;
    int l, r;
    cin >> t >> l >> r;
    calSuf(s + "$" + t);
    for (int i = 0; i < suf.size(); i++) {
      psum[i + 1] = (suf[i] > n) + psum[i];
    }
    for (int i = 0; i < suf.size(); i++) {
      if (suf[i] < n) {
        pair<int, int> bnd;
        int d = 0, u = n - suf[i] + 1;
        while (d < u - 1) {
          int mid = (d + u) / 2;
          pair<int, int> p = bound(i, mid);
          int c = psum[p.second + 1] - psum[p.first];
          if (c >= l)
            d = mid;
          else
            u = mid;
        }
        bnd.second = d;
        d = -1, u = n - suf[i];
        while (d < u - 1) {
          int mid = (d + u) / 2;
          pair<int, int> p = bound(i, mid);
          int c = psum[p.second + 1] - psum[p.first];
          if (c <= r)
            u = mid;
          else
            d = mid;
        }
        {
          pair<int, int> p = bound(i, u);
          int c = psum[p.second + 1] - psum[p.first];
          if (c <= r)
            bnd.first = u;
          else
            bnd.first = MAXN + 10;
        }
        cs[suf[i]].first = max(cs[suf[i]].first, bnd.first);
        cs[suf[i]].second = min(cs[suf[i]].second, bnd.second);
      }
    }
  }
  calSuf(s);
  for (int i = 1; i < n; i++) {
    cs[suf[i]].first = max(cs[suf[i]].first, lcp(suf[i - 1], suf[i]) + 1);
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) ans += max(0, cs[i].second - cs[i].first + 1);
  cout << ans << endl;
  return 0;
}
