#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-10;
template <typename T, typename S>
vector<T>& operator<<(vector<T>& a, S b) {
  a.push_back(b);
  return a;
}
template <typename T>
void operator>>(vector<T>& a, int b) {
  while (b--)
    if (!a.empty()) a.pop_back();
}
bool isprime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
long long b_pow(long long x, long long n) {
  return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll;
}
string itos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
string x[10];
int R[10];
int L[10];
int main() {
  string s;
  cin >> s;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> L[i] >> R[i];
  }
  set<int> v;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      unsigned long long y = 0;
      int len = j - i + 1;
      for (int k = 0; k < len; k++) y = y * 8999 + s[i + k];
      if (v.count(y)) continue;
      unsigned long long big = 1;
      for (int k = 0; k < len; k++) big *= 8999;
      int bad = 0;
      for (int k = 0; k < N; k++) {
        if (len > x[k].size()) {
          if (0 < L[k] || 0 > R[k]) {
            bad = 1;
            break;
          }
          continue;
        }
        int cnt = 0;
        unsigned long long sub = 0;
        for (int l = 0; l < len; l++) sub = sub * 8999 + x[k][l];
        if (sub == y) cnt++;
        for (int l = len; l < x[k].size(); l++) {
          sub = sub * 8999 + x[k][l];
          sub -= big * x[k][l - len];
          if (sub == y) {
            cnt++;
          }
        }
        if (cnt < L[k] || cnt > R[k]) {
          bad = 1;
          break;
        }
      }
      if (!bad) {
        ans++;
        v.insert(y);
      }
    }
  }
  cout << ans << endl;
}
