#include <bits/stdc++.h>
using namespace std;
string s;
string p[12];
int l[12], r[12];
map<string, int> mp, ms;
int gao(string a, string b) {
  int cnt = 0, mb = b.length(), ma = a.length();
  for (int i = 0; i < mb; i++) {
    if (b[i] != a[0]) continue;
    int fg = 1;
    for (int j = 0; j < ma; j++) {
      if (a[j] != b[j + i]) {
        fg = 0;
        break;
      }
    }
    if (fg) cnt++;
  }
  return cnt;
}
int main() {
  while (cin >> s) {
    mp.clear();
    ms.clear();
    int n, res = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> p[i] >> l[i] >> r[i];
    }
    int mx = s.length();
    for (int i = 0; i < mx; i++) {
      for (int j = i; j < mx; j++) {
        string sp = s.substr(i, j - i + 1);
        if (ms[sp]) continue;
        ms[sp] = 1;
        bool fg = true;
        for (int j = 0; j < n; j++) {
          int cnt = gao(sp, p[j]);
          if (cnt < l[j] || cnt > r[j]) {
            fg = false;
            break;
          }
        }
        if (fg) res++;
      }
    }
    cout << res << endl;
  }
  return 0;
}
