#include <bits/stdc++.h>
using namespace std;
char s[2002];
char A[12][2002];
int L[12], R[2002], tam[12][2002];
unsigned int HASH[10][2002][2002];
int main() {
  int n;
  while (scanf("%s", s) == 1) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%s %d %d", A[i], &L[i], &R[i]);
    int l = strlen(s);
    set<pair<int, unsigned int> > S;
    for (int i = 0; i < l; i++) {
      unsigned int H = 0;
      for (int j = i; j < l; j++) {
        H = H * 27 + (s[j] - 'a' + 1);
        S.insert(make_pair(j - i + 1, H));
      }
    }
    memset(tam, 0, sizeof(tam));
    for (int ii = 0; ii < n; ii++) {
      int t = strlen(A[ii]);
      for (int i = 0; i < t; i++) {
        unsigned int H = 0;
        for (int j = i; j < t; j++) {
          H = H * 27 + (A[ii][j] - 'a' + 1);
          HASH[ii][j - i + 1][tam[ii][j - i + 1]++] = H;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      int l = strlen(A[i]);
      for (int j = 0; j < l; j++) sort(HASH[i][j], HASH[i][j] + tam[i][j]);
    }
    vector<pair<int, unsigned int> > v(S.begin(), S.end());
    int size = v.size();
    int ans = 0;
    for (int i = 0; i < size; i++) {
      bool ok = 1;
      int t = v[i].first;
      unsigned int find = v[i].second;
      for (int j = 0; ok && j < n; j++) {
        long long g = upper_bound(HASH[j][t], HASH[j][t] + tam[j][t], find) -
                      lower_bound(HASH[j][t], HASH[j][t] + tam[j][t], find);
        if (L[j] <= g && g <= R[j]) continue;
        ok = 0;
      }
      if (ok) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}
