#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, long long> m[11];
map<long long, bool> M;
int main() {
  long long P[10001], l[11], r[11], ans = 0;
  string s, p[11];
  int n;
  cin >> s;
  cin >> n;
  P[0] = 1;
  for (int i = 1; i <= 10000; i++) P[i] = P[i - 1] * 63;
  for (int i = 1; i <= n; i++) {
    cin >> p[i] >> l[i] >> r[i];
    for (int j = 0; j < (int)p[i].length(); j++)
      for (int k = j; k < (int)p[i].length(); k++) {
        long long H = 0;
        for (int d = j; d <= k; d++) H += p[i][d] * P[d - j];
        m[i][make_pair(j, k)] = H;
      }
  }
  for (int i = 0; i < (int)s.length(); i++) {
    for (int j = i; j < (int)s.length(); j++) {
      bool ok = true;
      long long H = 0;
      for (int d = i; d <= j; d++) {
        H += s[d] * P[d - i];
      }
      if (M[H]) continue;
      for (int d = 1; d <= n; d++) {
        int cnt = 0;
        for (int k = 0; k < (int)((int)p[d].length() - j + i); k++) {
          if (m[d][make_pair(k, k + j - i)] == H) cnt++;
        }
        if (cnt < l[d] || cnt > r[d]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        ans++;
        M[H] = true;
      }
    }
  }
  cout << ans;
}
