#include <bits/stdc++.h>
using namespace std;
string s1;
string s[15];
int l[15], r[15], n;
set<string> sss;
int main() {
  int i, j, k;
  cin >> s1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i] >> l[i] >> r[i];
  }
  int ans = 0;
  for (i = 1; i <= s1.length(); i++) {
    for (j = 0; j <= s1.length() - i; j++) {
      bool f = 1;
      string s2 = s1.substr(j, i);
      for (k = 1; k <= n; k++) {
        int ll = 0;
        int p = 0, q;
        while (p < s[k].length() && (s[k].find(s2, p)) != string::npos) {
          ll++;
          p = s[k].find(s2, p) + 1;
        }
        if (ll < l[k] || ll > r[k]) {
          f = 0;
          break;
        }
      }
      if (f) {
        if (sss.find(s2) == sss.end()) {
          ans++;
          sss.insert(s2);
        }
      }
    }
  }
  cout << ans << endl;
}
