#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
template <class T>
T inline sqr(T x) {
  return x * x;
}
const double pi = 3.1415926535897932384626433832795;
const double eps = 1e-8;
struct rule {
  int l, r;
  string p;
};
const int maxn = 2015;
vector<rule> rules;
const long long pr = 239;
long long deg[maxn];
int q(const string& s, int st, int fin, const string& t) {
  int len = fin - st;
  if (t.size() < len + 1) return 0;
  long long hs = 0, p = 1;
  for (int i = st; i <= fin; i++) {
    hs += (s[i] - 'a' + 1) * p;
    p *= pr;
  }
  vector<long long> h(t.size() + 1);
  p = 1;
  for (int i = 1; i <= t.size(); i++) {
    h[i] = h[i - 1] + deg[i - 1] * (t[i - 1] - 'a' + 1);
  }
  int res = 0;
  for (int i = 0; i < t.size() - len; i++)
    if (h[i + len + 1] - h[i] == hs * deg[i]) res++;
  return res;
}
int main() {
  string s;
  int n;
  deg[0] = 1;
  for (int i = 1; i < maxn; i++) deg[i] = deg[i - 1] * pr;
  cin >> s >> n;
  for (int i = 0; i < n; i++) {
    rule r;
    cin >> r.p >> r.l >> r.r;
    rules.push_back(r);
  }
  set<string> S;
  for (int i = 0; i < s.length(); i++) {
    int maxr = i, minl = s.length() - 1;
    for (int j = 0; j < n; j++) {
      int left, right, middle;
      left = i, right = s.size();
      if (q(s, i, i, rules[j].p) < rules[j].l) {
        maxr = minl + 1;
        break;
      }
      while (left + 1 < right) {
        middle = (left + right) / 2;
        if (q(s, i, middle, rules[j].p) >= rules[j].l)
          left = middle;
        else
          right = middle;
      }
      minl = min(minl, left);
      left = i - 1, right = s.size();
      while (left + 1 < right) {
        middle = (left + right) / 2;
        if (q(s, i, middle, rules[j].p) <= rules[j].r)
          right = middle;
        else
          left = middle;
      }
      maxr = max(maxr, right);
    }
    if (maxr <= minl)
      for (int j = maxr; j <= minl; j++) S.insert(s.substr(i, j - i + 1));
  }
  cout << S.size();
  return 0;
}
