#include <bits/stdc++.h>
using namespace std;
string s, p[1111], t;
int l[111], r[111], n, pp[1111], res;
map<string, bool> m;
int main() {
  cin >> s;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i] >> l[i] >> r[i];
  for (int i = 0; i < ((int)(s).size()); i++) {
    t = "";
    for (int j = i; j < ((int)(s).size()); j++) {
      t += s[j];
      int y = 0;
      if (m.find(t) == m.end()) {
        m[t] = 1;
        for (int h = 1; h <= n; h++) {
          string tt = t;
          tt += '#';
          tt += p[h];
          for (int u = 0; u <= ((int)(tt).size()); u++) pp[u] = 0;
          for (int u = 1; u < ((int)(tt).size()); u++) {
            int k = pp[u - 1];
            while (k > 0 && tt[k] != tt[u]) k = pp[k - 1];
            if (tt[u] == tt[k]) k++;
            pp[u] = k;
          }
          int o = 0;
          for (int u = 0; u < ((int)(tt).size()); u++)
            if (pp[u] == ((int)(t).size())) o++;
          if (l[h] <= o && o <= r[h]) y++;
        }
        if (y == n) {
          res++;
        }
      }
    }
  }
  cout << res;
  return 0;
}
